-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
40 lines (32 loc) · 854 Bytes
/
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
'use strict';
var koa = require('koa');
var compress = require('koa-compress');
var logger = require('koa-logger');
var cors = require('koa-cors');
var httpError = require('http-errors');
function *handleErrors(next) {
try {
yield next;
} catch (err) {
this.status = err.status || 500;
this.body = {message: err.message};
}
}
var app = koa();
app.use(logger());
app.use(handleErrors);
app.use(cors({
headers: ['Authorization', 'Origin', 'X-Requested-With', 'Content-Type', 'Accept', 'x-csrf-token'],
}));
app.use(require('./routes').routes());
app.use(compress());
// app.on('error', function(error) {
// console.error(error.message);
// // console.error(error.stack)
// });
module.exports = app;
if (!module.parent) {
var port = process.env.PORT || 3002;
app.listen(port);
console.log('listening on port', port);
}