-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
46 lines (41 loc) · 1.09 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
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Main Application File
*/
import restify from 'restify';
import config from './config/environment';
import restifyConfig from './config/restify';
import routes from './config/routes';
import database from './config/database';
// Setup Server
const server = restify.createServer({
name: 'classicaldb-metadata',
versions: ['1.0.0'],
});
// Configure Restify and Routes
restifyConfig(server);
routes(server);
// Export this function so that it can be used inside of tests
export function boot(port) {
return new Promise((resolve) => {
// Create Database Connection
database.sequelize.sync()
.then(() => {
if (config.env === 'test_local' || config.env === 'test_ci') {
resolve(server.listen(port));
} else {
resolve(server.listen(port, config.ip, () => {
// TODO: implement good logging
console.log(
'Restify server listening on %d, in %s mode',
config.port,
config.env
);
}));
}
})
.catch((err) => {
// TODO: implement good logging
console.error(err);
});
});
}