-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (31 loc) · 872 Bytes
/
server.js
File metadata and controls
34 lines (31 loc) · 872 Bytes
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
const express = require('express');
const mongodb = require('mongodb');
const swapi = require('swapi-node');
const initSystem = require('./system');
const app = express();
const args = process.argv;
const shouldMock = (args.length === 3 && args[2] === '--mock');
const swapiMock = {
get: (link) => ({ name:link })
};
const api = shouldMock ? swapiMock : swapi;
const config = {
app: {
port: process.env.PORT || 8080
},
mongo: {
options: {
auth: {
user: process.env.MONGO_DB_APP_USERNAME || 'node',
password: process.env.MONGO_DB_APP_PASSWORD || 'node'
},
keepAlive: true,
reconnectTries: 30,
socketTimeoutMS: 0
}
}
};
const system = initSystem({ mongodb, app, swapi: api, config });
system.start()
.then(() => console.log(`Server listening at localhost:${config.app.port}`))
.catch(console.error);