This repository was archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathserver.js
More file actions
57 lines (48 loc) · 1.43 KB
/
server.js
File metadata and controls
57 lines (48 loc) · 1.43 KB
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
54
55
56
57
import './environment';
import Module from './Module';
import cluster from 'cluster';
import coordinator from './coordinator';
import createGetComponent from './createGetComponent';
import express from 'express';
import getFiles from './getFiles';
import loadModules from './loadModules';
import logger from './utils/logger';
import createVM from './createVM';
import worker from './worker';
const defaultConfig = {
bodyParser: {
limit: 1024 * 1000,
},
endpoint: '/batch',
enableCluster: false,
files: [],
logger: {},
plugins: [],
port: 8080,
};
export default function hypernova(userConfig, onServer) {
const config = Object.assign({}, defaultConfig, userConfig);
if (typeof config.getComponent !== 'function') {
throw new TypeError('Hypernova requires a `getComponent` property and it must be a function');
}
logger.init(config.logger);
const app = express();
if (config.enableCluster) {
if (cluster.isMaster) {
coordinator();
} else {
worker(app, config, onServer, cluster.worker.id);
}
} else {
worker(app, config, onServer);
}
return app;
}
// I'm "exporting" them here because I want to export these but still have a default export.
// And I want it to work on CJS.
// I want my cake and to eat it all.
hypernova.Module = Module;
hypernova.createGetComponent = createGetComponent;
hypernova.createVM = createVM;
hypernova.getFiles = getFiles;
hypernova.loadModules = loadModules;