A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.
Nest framework TypeScript starter repository.
$ yarn
# development
$ yarn start
# watch mode
$ yarn dev
# production mode
$ yarn prod
# create empty migration
$ yarn migration:create migration-name
# auto create migration
$ yarn migration:generate migration-name
# apply migrations
$ yarn migration:run
# revert migration
$ yarn migration:revert
- Swagger API documentation
- Authenticated with JWT by default
- Using simple Attribute-based Access Control (ABAC)
This project using @nestjs/swagger
. Go to http://localhost:8000/docs to access Swagger UI.
Read more at https://github.com/nestjs/swagger.
All routes in this project will be authentication required by default. To public any route, using @Public()
decorator.
// This route will be public. Everyone can access this route
@Controller('something')
export class ExampleController {
@Get()
@Public()
publicRoute() {
return 'Hello!'
}
}
This project using ABAC to control access. @AccessControl()
will check user role before access to route.
// This route will be protected. Anyone have 'user:view:any' permission can access this route
@Controller('something')
export class ExampleController {
@Get()
@AccessControl({
resource: 'user',
action: 'view',
possession: 'any'
})
protectedRoute() {
return 'Hello'
}
}
Database will be like following tables:
users | ||
---|---|---|
id | int(11) | PRIMARY KEY AUTO_INCREMENT |
username | varchar(255) | |
password | varchar(255) | |
salt | varchar(255) | |
varchar(255) | ||
... | ... |
roles | ||
---|---|---|
id | int(11) | PRIMARY KEY AUTO_INCREMENT |
key | varchar(255) | |
name | varchar(255) | |
description | varchar(255) |
users_roles_roles | ||
---|---|---|
userId | int(11) | PRIMARY KEY FOREIGN KEY |
roleId | int(11) | PRIMARY KEY FOREIGN KEY |
roles-permissions | ||
---|---|---|
id | int(11) | PRIMARY KEY AUTO_INCREMENT |
role | int(11) | FOREIGN KEY |
permission | varchar(255) | |
description | varchar(255) |
Nest is MIT licensed.