-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (26 loc) · 823 Bytes
/
index.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';
let Promise = require('bluebird');
let http = require('http');
let fs = require('fs');
let path = require('path');
let Koa = require('koa');
let router = require('./app/router');
let port = process.port || 8080;
let defer = Promise.defer();
const app = new Koa();
// Middlewares
var bodyParser = require('koa-bodyparser');
app.use(bodyParser());
// Initializers
['is', 'error-handler', 'database', 'basic-auth'].map(fileName => {
let filePath = path.join(__dirname, 'initializers', fileName);
let middleware = require(filePath);
if (middleware) app.use(middleware());
});
app.use(router.routes());
let server = http.createServer(app.callback());
server.listen(port, () => {
console.log(`Start Server At ${port}\n`);
defer.resolve(server);
});
module.exports = defer.promise;