39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
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();
|