my blog api with nodejs
# Install dependencies
npm install
# Start the api server(dev)
npm run start
# Start the api server(pro)
npm run pm2
#...
Add admin http://localhost:4000/api/backend
After the success of the administrator to add, will automatically generate the admin.
Lock file locking, if you need to continue to add, please just delete the file
note:get more details on api-docs(todos).
|--README.md #read me before
|--app.js #the app index file
|--bin #run the app index file
| |--www
|--license
|--package.json
|--server
| |--api #some api handle files
| | |--backend-article.js
| | |--backend-category.js
| | |--backend-user.js
| | |--frontend-article.js
| | |--frontend-comment.js
| | |--frontend-like.js
| | |--frontend-user.js
| | |--general.js
| |--config #some config for cunstom app
| | |--index.js
| | |--mpapp.js
| | |--secret.js
| |--middlewares #some custom middlewares files
| | |--admin.js
| | |--check.js
| | |--user.js
| |--models #some data model files
| | |--admin.js
| | |--article.js
| | |--category.js
| | |--comment.js
| | |--user.js
| |--mongoose.js # connect database
| |--routes # map the url path to handle files/functions with router
| | |--backend.js
| | |--frontend.js
| | |--index.js
| |--utils #some useful tool
|--views #some views
|--admin-add.ejs
|--favicon.ico
- map the url path to handle files/functions with route
- connect database
req url->route->model->view->res uri
admin:
// ================ admin ================
// this is a custom express middleware admin
// ================ admin ================
// task:
// check if user is admin:
// 01.need to login first
// 02.need to check the user
// if true,goto next middleware
user:
// ================ user ================
// this is a custom express middleware user
// ================ user ================
// task:
// check if user is user:
// 01.need to login first
// 02.need to check the user
// if true,goto next middleware
return:
// ================ return ================
// this is a custom express middleware return
// ================ return ================
// task:
// bind error,success function to ctx to uniform the return result
// and goto next middleware