-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (40 loc) · 1.13 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
var koa = require('koa'),
logger = require('koa-logger'),
Router = require('koa-router'),
session = require('koa-generic-session'),
RedisStore = require('koa-redis'),
csrf = require('koa-csrf'),
parse = require('co-body'),
serve = require('koa-static'),
passport = require('./routes/auth'),
config = require('./config');
// Setup Application
var app = module.exports = koa();
app.keys = config.keys;
csrf(app);
// Setup middleware
app.use(logger());
app.use(session({
store: new RedisStore()
}));
// Parse every post request and save it in ctx.request.body
app.use(function *bodyParser(next){
if ('POST' !== this.method) return yield next;
var body = yield parse(this);
this.request.body = body;
yield next;
});
app.use(csrf.middleware);
app.use(passport.initialize());
app.use(passport.session());
app.use(serve('static'));
app.use(Router(app));
// Routes
require('./router')(app);
if (!module.parent) {
var server = app.listen(config.httpPort);
require('./lib/Streaming').initSockjs
(server);
console.log('Listening on port', config.httpPort);
// require('./lib/thriftStreaming');
}