|
|
2 jaren geleden | |
|---|---|---|
| .vscode | 2 jaren geleden | |
| certs | 2 jaren geleden | |
| src | 2 jaren geleden | |
| templates | 2 jaren geleden | |
| test | 2 jaren geleden | |
| views | 2 jaren geleden | |
| .env | 2 jaren geleden | |
| .env.production | 2 jaren geleden | |
| .eslintrc.js | 2 jaren geleden | |
| .gitignore | 2 jaren geleden | |
| .prettierrc | 2 jaren geleden | |
| LICENSE | 2 jaren geleden | |
| README.md | 2 jaren geleden | |
| build.sh | 2 jaren geleden | |
| docker-compose.yml | 2 jaren geleden | |
| fix.js | 2 jaren geleden | |
| g.mjs | 2 jaren geleden | |
| graph.json | 2 jaren geleden | |
| nest-cli.json | 2 jaren geleden | |
| package-lock.json | 2 jaren geleden | |
| package.json | 2 jaren geleden | |
| pem.mjs | 2 jaren geleden | |
| tsconfig.build.json | 2 jaren geleden | |
| tsconfig.json | 2 jaren geleden | |
| typeorm-cli.config.ts | 2 jaren geleden | |
| yarn.lock | 2 jaren geleden |
An API Boilerplate to create a ready-to-use REST API in seconds with NestJS 9.x and JWT Auth System :heart_eyes_cat:
$ npm install
$ cp .env.example .env
To set up on multiple environments, such as dev, stage or prod, we do as follows:
$ cp .env.example .env.dev # or .env.stage, etc
EMAIL_HOST=smtp.mailtrap.io
EMAIL_PORT=2525
EMAIL_AUTH_USER=[:user]
EMAIL_AUTH_PASSWORD=[:password]
EMAIL_DEBUG=true
EMAIL_LOGGER=true
EMAIL_LAYOUT_DIR='templates/emails/'
EMAIL_PARTIAL_DIR='templates/emails/'
EMAIL_VIEW_PATH='/templates/emails/'
EMAIL_DEFAULT_LAYOUT='index'
Once the database has been configured, start the Nest App via npm run start:dev it automatically synchronizes the entities so ready to use. :heart_eyes_cat:
TYPEORM_CONNECTION = "mysql"
TYPEORM_HOST = "localhost"
TYPEORM_PORT = 3306
TYPEORM_USERNAME = [:user]
TYPEORM_PASSWORD = [:password]
TYPEORM_DATABASE = [:database]
TYPEORM_AUTO_SCHEMA_SYNC = true
TYPEORM_ENTITIES = "dist/**/*.entity.js"
TYPEORM_SUBSCRIBERS = "dist/subscriber/**/*.js"
TYPEORM_MIGRATIONS = "dist/migrations/**/*.js"
TYPEORM_ENTITIES_DIR = "src/entity"
TYPEORM_MIGRATIONS_DIR = "src/migration"
TYPEORM_SUBSCRIBERS_DIR = "src/subscriber"
$ npm install -g ts-node
$ ts-node node_modules/.bin/typeorm migration:run -d dist/typeorm-cli.config
or
$ node_modules/.bin/typeorm migration:run -d dist/typeorm-cli.config
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
$ npm run start -- --entryFile repl
or
$ npm run start:repl
There is a docker-compose.yml file for starting MySQL with Docker.
$ docker-compose up db
After running, you can stop the Docker container with
$ docker-compose down
http://127.0.0.1:3000/docs
or
http://127.0.0.1:3000/docs-json
or
http://127.0.0.1:3000/docs-yaml
Configure SWAGGER_USER and SWAGGER_PASSWORD in the .env file and set NODE_ENV to local or devor staging to access the SWAGGER(Open Api) documentation with basic authentication.
NODE_ENV=[:enviroments]
SWAGGER_USER=[:user]
SWAGGER_PASSWORD=[:password]
````
If you want to add more environments, include them in the `SWAGGER_ENVS` array in `main.ts`, see the following:
typescript const SWAGGER_ENVS = ['local', 'dev', 'staging']; ````
NODE_API_PORT=3333
ENDPOINT_CORS='http://127.0.0.1:4200'
$ curl -H 'content-type: application/json' -v -X GET http://127.0.0.1:3000/api/secure -H 'Authorization: Bearer [:token]'
$ curl -H 'content-type: application/json' -v -X POST -d '{"email": "tony_admin@nest.it", "password": "secret"}' http://127.0.0.1:3000/api/auth/login
$ curl -H 'content-type: application/json' -v -X POST -d '{"name": "tony", "email": "tony_admin@nest.it", "username":"tony_admin", "password": "secret"}' http://127.0.0.1:3000/api/auth/register
$ curl -H 'content-type: application/json' -v -X POST -d '{"email": "tony_admin@nest.it"}' http://127.0.0.1:3000/api/auth/forgot-password
$ curl -H 'content-type: application/json' -v -X POST -d '{"email": "tony_admin@nest.it", "password": "secret123"}' http://127.0.0.1:3000/api/auth/change-password -H 'Authorization: Bearer [:token]'
$ curl -H 'content-type: application/json' -v -X PUT -d '{"name": "tony", "email": "tony_admin@nest.it", "username": "tony_admin"}' http://127.0.0.1:3000/api/users/:id/profile -H 'Authorization: Bearer [:token]'
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X GET http://127.0.0.1:3000/api/users -H 'Authorization: Bearer [:token]'
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X GET http://127.0.0.1:3000/api/users/:id -H 'Authorization: Bearer [:token]'
$ curl -H 'content-type: application/json' -v -X PATCH -d '{"name": "tony", "email": "tony_admin@nest.it", "username": "tony_admin", "password":"secret"}' http://127.0.0.1:3000/api/users/:id -H 'Authorization: Bearer [:token]'
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X DELETE http://127.0.0.1:3000/api/users/:id -H 'Authorization: Bearer [:token]'