index.js
869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* web ui 模块
*
* @author: jiang
*/
import path from 'path';
import Koa from 'koa';
import convert from 'koa-convert';
import hbs from '../../middleware/yoho-koa-hbs';
import helpers from '../../lib/helpers';
import routers from './routers'
const app = new Koa();
app.use(hbs({
views: path.join(__dirname, '/views'),
defaultLayout: 'layout',
helpers: helpers
}));
app.use(async(ctx, next) => {
ctx.locals = {
title: 'Yoho Node.js 持续集成平台'
};
let pjax = ctx.request.get('X-PJAX');
if (pjax) {
ctx.locals.layout = null;
}
await next();
// if (pjax && ctx.status == 301) {
// let location = ctx.response.get('Location');
// ctx.response.set('X-PJAX-URL', ctx.origin + location);
// }
ctx.response.set('X-PJAX-URL', ctx.href);
});
routers(app);
export default app;