|
| 1 | +<br /> |
| 2 | +<p align="center"> |
| 3 | + <img width="25%" height="25%" src="./logo.png"> |
| 4 | +</p> |
| 5 | + |
| 6 | +<h1 align="center">Nx Serverless</h1> |
| 7 | + |
| 8 | +> The Ultimate Monorepo Starter for Node.js Serverless Applications |
| 9 | +
|
| 10 | +✅ First-Class Typescript Support<br> |
| 11 | +✅ DynamoDB Single Table Design<br> |
| 12 | +✅ Shared API Gateway<br> |
| 13 | +✅ Enviroments Configuration<br> |
| 14 | +✅ JWT Auth Middleware<br> |
| 15 | +✅ Http Params Validation<br> |
| 16 | +✅ Typed Proxy Handlers<br> |
| 17 | +✅ Auto Generators<br> |
| 18 | +✅ Localstack<br> |
| 19 | +✅ ESLint<br> |
| 20 | +✅ Jest |
| 21 | + |
| 22 | +<hr /> |
| 23 | + |
| 24 | +[](http://www.serverless.com) |
| 25 | +[](https://nx.dev/) |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +[](https://github.com/sudokar/nx-serverless/blob/master/LICENSE) |
| 30 | +[](https://github.com/sudokar/nx-serverless) |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +## Prerequisites |
| 35 | + |
| 36 | +- Docker |
| 37 | +- Node.js |
| 38 | + |
| 39 | +## Getting Started |
| 40 | + |
| 41 | +- Run git clone https://github.com/ngneat/nx-serverless.git your-app-name |
| 42 | +- Run `npm install` |
| 43 | +- Run `npm run localstack` |
| 44 | +- Update the `environment` files based on your configuration. |
| 45 | +- Run `npm run serve` |
| 46 | + |
| 47 | +## About the App |
| 48 | + |
| 49 | +The application contains three services: |
| 50 | + |
| 51 | +#### Auth Service: |
| 52 | + |
| 53 | +The auth service is responsible for authentication. It exposes one route for signing up: |
| 54 | + |
| 55 | +```bash |
| 56 | +curl --request POST 'http://localhost:3001/dev/auth/sign-up' \ |
| 57 | +--data-raw '{ |
| 58 | + "email": "netanel@gmail.com", |
| 59 | + "name": "Netanel Basal" |
| 60 | +}' |
| 61 | +``` |
| 62 | + |
| 63 | +The request returns a JWT, which is used for accessing protected routes. |
| 64 | + |
| 65 | +#### Users Service: |
| 66 | + |
| 67 | +The users service is responsible for managing users. It exposes one route: |
| 68 | + |
| 69 | +```bash |
| 70 | +curl 'http://localhost:3003/dev/user' --header 'Authorization: token TOKEN' |
| 71 | +``` |
| 72 | + |
| 73 | +The request returns the logged-in user. |
| 74 | + |
| 75 | +#### Todos service: |
| 76 | + |
| 77 | +The todos service is responsible for managing todos. A user has many todos. It exposes CRUD routes: |
| 78 | + |
| 79 | +```bash |
| 80 | +// Get user todos |
| 81 | +curl 'http://localhost:3005/dev/todos' --header 'Authorization: token TOKEN' |
| 82 | + |
| 83 | +// Get single todo |
| 84 | +curl 'http://localhost:3005/dev/todos/:id' --header 'Authorization: token TOKEN' |
| 85 | + |
| 86 | +// Create a todo |
| 87 | +curl --request POST 'http://localhost:3005/dev/todos' \ |
| 88 | +--header 'Authorization: token TOKEN' |
| 89 | +--data-raw '{ |
| 90 | + "title": "Learn Serverless" |
| 91 | +}' |
| 92 | + |
| 93 | +// Update a todo |
| 94 | +curl --request PUT 'http://localhost:3005/dev/todos/01G2HGJADWKDPKWHJAVZJ1QP9S' \ |
| 95 | +--header 'Authorization: token TOKEN' \ |
| 96 | +--data-raw '{ |
| 97 | + "completed": true |
| 98 | +}' |
| 99 | +``` |
| 100 | + |
| 101 | +## Commands |
| 102 | + |
| 103 | +```bash |
| 104 | +nx serve <service-name> |
| 105 | +nx deploy <service-name> |
| 106 | +nx remove <service-name> |
| 107 | +nx build <service-name> |
| 108 | +nx lint <service-name> |
| 109 | +nx test <service-name> |
| 110 | + |
| 111 | +// Use different enviroment |
| 112 | +NODE_ENV=prod nx deploy <service-name> |
| 113 | +NODE_ENV=stg nx deploy <service-name> |
| 114 | + |
| 115 | +// Run only affected |
| 116 | +nx affected:test |
| 117 | +nx affected:deploy |
| 118 | +``` |
| 119 | + |
| 120 | +## Generators |
| 121 | + |
| 122 | +```bash |
| 123 | +// Generate a service |
| 124 | +npx nx workspace-generator service tags |
| 125 | + |
| 126 | +// Generate handler |
| 127 | +npx nx workspace-generator handler --name=create-tag --project=tags |
| 128 | + |
| 129 | +// Generate http handler |
| 130 | +npx nx workspace-generator http-handler --name=create-tag --project=tags |
| 131 | + |
| 132 | +// Generate a model |
| 133 | +npx nx workspace-generator model --name=tag --project=tags |
| 134 | +``` |
| 135 | + |
| 136 | +## Further help |
| 137 | + |
| 138 | +- Visit [Serverless Documentation](https://www.serverless.com/framework/docs/) to learn more about Serverless framework |
| 139 | +- Visit [Nx Documentation](https://nx.dev) to learn more about Nx dev toolkit |
| 140 | + |
| 141 | +## Contribution |
| 142 | + |
| 143 | +Found an issue? feel free to raise an issue with information to reproduce. |
| 144 | + |
| 145 | +Pull requests are welcome to improve. |
| 146 | + |
| 147 | +## License |
| 148 | + |
| 149 | +MIT |
| 150 | + |
| 151 | +This project is a fork of [nx-serverless](https://github.com/sudokar/nx-serverless) |
| 152 | + |
| 153 | +<a href="https://www.flaticon.com/free-icons/monster" title="monster icons">Monster icons created by Smashicons - Flaticon</a> |
0 commit comments