-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.js
33 lines (33 loc) · 1.01 KB
/
server.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
/**
* This is the top level call for the underlying connect server
* The main export module will wrap that in stream
* This way, we have two different ways to use this module
*/
const _ = require('lodash');
const { serveStatic } = require('./src/lib/utils/helper');
const appGenerator = require('./src/lib/app');
const serverGenerator = require('./src/lib/webserver');
const disable = {
open: false,
reload: false,
debugger: false,
development: false
};
// Export
module.exports = function(options = {}) {
// We always overwrite it here to disable feature that shouldn't be use
if (!options.development) {
options = _.merge(options, disable);
}
// Generate the app
const { app, config, mockServerInstance } = appGenerator(options);
// Static serving
app.use(config.path, serveStatic(config.webroot, config));
// Configure the server
let webserver = serverGenerator(app, config);
webserver.on('close', () => {
mockServerInstance.close();
// DebuggerInstance.close();
});
return webserver;
};