代码拉取完成,页面将自动刷新
const Koa = require('koa');
const views = require('koa-views');
const koaStatic = require('koa-static');
const Router = require('koa-router');
const path = require('path');
const router = new Router();
router.get('/', async (ctx) => {
await ctx.render('index');
});
router.get('/detail/*', async (ctx) => {
await ctx.render('index');
});
const app = new Koa();
// x-response-time
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
});
// logger
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}`);
});
// template
app.use(views(path.join(__dirname, './views'), {
extension: 'html',
}));
app.use(koaStatic(`${__dirname}`));
app.use(router.routes())
.use(router.allowedMethods());
app.listen(9001);
console.log(`listening on port ${9001}`);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。