-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (36 loc) · 846 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
41
42
43
44
45
46
47
48
49
'use strict';
import koa from 'koa';
import body from 'koa-body';
import validate from 'koa-validate';
import routes from './routes/routes';
import config from './config';
function start() {
let app = koa();
app.use(function*(next) {
try {
yield next;
}
catch (err) {
this.status = err.status || 500;
this.body = err.message;
this.app.emit('error', err, this);
}
});
app.on('error', (err) => {
console.error('ERROR: '+ err);
});
// register body parser
app.use(body());
// register validator middleware
app.use(validate());
// register routes
app.use(routes.getRoutes());
// used when accessing root or any unregistered end-point
app.use(function *() {
this.body = 'Tweet tweet... API root';
});
app.listen(config.app.port);
}
export default {
start
};