Rest is a simple Typescript Koa2 api stater. It's my first typescript program and is a project aim to reduce my development costs
- Koa
- Joi
- PassportJS
The design of this restful api has been inspired by this article Project structure for an Express REST API when there is no “standard way”.The architecture diagram below shows the main idea.
Controllers: You should never put any logic in controller layer. They call the service
, which contain pure business logic
Service: should contain the majority of your business logic, that calls your data access layer or model
To create an new project you will need to init sequelize model. Please read Sequelize migrations for futher information. Once you finished your database initiation, modify smaple/example.js
and copy into your rest/component/<something>
folder
module alias
// "_moduleAliases": {
// "@config": "<rootDir>/src/config",
// "@interfaces": "<rootDir>/src/interfaces",
// "@services": "<rootDir>/src/services",
// "@components": "<rootDir>/src/rest/components"
// },
Alias |
---|
@config |
@interface |
@services |
run SET NODE_ENV=<DEV|PROD>
in cmd then run npm run start