Skip to content

jaxzhou/node_api_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-api-template

App

npm install
npm start

Middlewares

Add Middelware Code in ./src/middlewares and exports aysnc function (ctx, next)

sample:

module.exports = aysnc function(ctx, next) {
	console.info('let start at beginning');
	await next();
	console.info('let start at end');
}

Controllers

  1. Add Controller Code in ./src/controllers and export Controller Class
\\ MyController.js
class MyController {

}
module.exports = MyController
  1. Add Route Annotation to Controller function
const Controller = require('./index');
const route = Controller.route;
const auth = Controller.auth;

class MyController {
	@route('GET', '/something')
	async doSomthing(ctx, next) {
		ctx.body = 'do something';
	}

	@route('GET', '/somethingNeedAuth')
	@auth()
	async doSomthingNeedAuth(ctx, next) {
		ctx.body = 'do something need auth';
	}
}

Run With PM2

pm2 start api.config.js

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors