1 Star 0 Fork 0

yardwill/react-ts-webpack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server.js 960 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yard 提交于 2018-02-12 13:04 . v
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}`);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/yardwill/react-ts-webpack.git
git@gitee.com:yardwill/react-ts-webpack.git
yardwill
react-ts-webpack
react-ts-webpack
master

搜索帮助