-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
70 lines (42 loc) · 1.6 KB
/
app.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const Koa = require('koa');
const bodyParser = require('koa-bodyparser'); //这玩意用来解析请求体中的json
const controller = require('./controller');
const koaBetterBody = require('koa-better-body'); //这玩意能解析form表单,body里面直接.拿数据
const templating = require('./templating');
const rest = require('./rest');
const websocket = require('./websocket');
const session = require('koa-session');
var socketio =require('./socketIo');
const CONFIG = require( './config' );
const app = new Koa();
app.keys = ['BUPT 3DPlatform BY CJX'];
app.use(session(CONFIG.session,app));
// log request URL:
app.use(async (ctx, next) => {
console.log(`Process ${ctx.request.method} ${ctx.request.url}...`);
await next();
});
// static file support:
let staticFiles = require('./static-files');
app.use(staticFiles('/static/', __dirname + '/static'));
app.use(staticFiles('/public/', __dirname + '/public'));
// parse request body:
app.use(koaBetterBody({ //注册解析form的中间件,现在可以解析form-data,x-www,json
fields: 'body', //中间件位置真的很重要,这个放在parser前面就可以完美解析
})); //最大尺寸200M
app.use(bodyParser());
// add nunjucks as view:
app.use(templating('views', {
noCache: true,
watch: true
}));
// bind .rest() for ctx:
app.use(rest.restify());
// add controllers:
app.use(controller());
let server = app.listen(8800);
socketio(app.listen(8000))
app.wss = websocket(server);
global.wss = app.wss;
console.log('app started at port 8800...'); //这是一个注释A
//module.exports = app;