-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
53 lines (40 loc) · 1.17 KB
/
index.ts
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
const debug = require('debug')('easy-server');
import express = require('express');
import MiddlewareManager = require('middleware-manager');
import start = require('./start');
import { Options, Server } from './shared/server';
function easyServer(options: Options): Server {
const app: Server = <any>express();
app.start = start.bind(null, app);
app.easyOptions = {
middleware: './app/middleware',
controllers: './app/controllers',
port: 8080,
autoStart: true,
debug,
extensions: ['.js'],
keepAliveTimeout: 120000,
};
Object.keys(options).forEach(key => {
if (options.hasOwnProperty(key)) {
app.easyOptions[key] = options[key];
}
});
(app as any).on('connection', function (socket) {
socket.setTimeout(app.easyOptions.keepAliveTimeout);
});
app.debug = app.easyOptions.debug;
app.middleware = new MiddlewareManager();
if (app.easyOptions.autoStart === true) {
app.start();
}
if (app.easyOptions.cors === true) {
app.use(require('./shared/cors'));
app.debug('Added CORS middleware');
}
return app;
}
module easyServer {
export interface Application extends Server { }
}
export = easyServer;