Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

【模范代码】入口index.js

import "./lib/utils/config.js";
import { Log } from "./lib/utils/api_log.js";
const log = new Log("index");

import Koa from 'koa';

import setCommon from  "./lib/middleware/setCommon.js";
import setRouter from "./lib/middleware/setRouter.js";
import { verifyToken } from "./lib/utils/api_token.js";

const app = new Koa();

await setCommon(app);
await setRouter(app, '/lib/router/v1/no_login/');

//鉴权中间件
app.use(async (ctx, next) => {
    if(verifyToken(ctx)){
        await next();
    }
})

await setRouter(app, '/lib/router/v1/need_auth/');

// 启动服务器
const port = 8060;
log.info("");
log.info(`server started at ${port}`)
log.info("");
app.listen(port);