-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
index.js
28 lines (24 loc) · 848 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
const
http = require('http'),
logger = require('morgan')('combined'),
port = process.env.PORT || 3000,
runningInDevMode = `${ process.env.NODE_ENV }`.toLocaleLowerCase() === 'test',
{ requestHandler } = runningInDevMode ? inMemoryServer() : compiledServer(),
server = http.createServer(requestHandler.use(logger));
server.listen(port, () => {
console.log(`Calculator server started on port ${ port }`)
});
// ---
function inMemoryServer() {
require('ts-node/register');
return require('./src/rest-api');
}
function compiledServer() {
try {
return require('./lib/rest-api');
}
catch(e) {
console.error('Remember to compile the module before trying to start the server: npm run compile');
process.exit(1);
}
}