start
This commit is contained in:
38
routes/index.js
Normal file
38
routes/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import Router from 'koa-router';
|
||||
import { HandlerUser } from '../handler/users.js';
|
||||
|
||||
class ApiRouter {
|
||||
constructor() {
|
||||
this.router = new Router();
|
||||
this.handler = new HandlerUser();
|
||||
this.setupRoutes();
|
||||
}
|
||||
|
||||
setupRoutes() {
|
||||
const userRouter = new Router({ prefix: '/user' });
|
||||
|
||||
userRouter.post('/wxgetphonenumber', this.handler.wxGetPhoneNumber.bind(this.handler));
|
||||
userRouter.post('/wxsignin', this.handler.wxSignin.bind(this.handler));
|
||||
userRouter.post('/update', this.handler.updateUser.bind(this.handler));
|
||||
userRouter.post('/signout', this.handler.signout.bind(this.handler));
|
||||
|
||||
this.router.use(userRouter.routes());
|
||||
|
||||
this.printRoutes(this.router.stack);
|
||||
}
|
||||
|
||||
getRoutes() {
|
||||
return this.router.routes();
|
||||
}
|
||||
|
||||
printRoutes(stack) {
|
||||
for (const layer of stack) {
|
||||
if (layer.path) {
|
||||
const methods = layer.methods.filter(m => m !== '_all');
|
||||
methods.forEach(m => console.log(` [${m.toUpperCase()}] ${layer.path}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new ApiRouter();
|
||||
Reference in New Issue
Block a user