-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (38 loc) · 963 Bytes
/
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
'use strict';
const Hapi = require('hapi');
require('dotenv').config();
global.appRequire = function(name) {
return require(__dirname + '/app/' + name);
}
global.loadConfig = function() {
return appRequire('config');
}
global.loadDb = function(name) {
return appRequire('db/'+name);
}
global.loadHelpers = function(name) {
return appRequire('helpers/'+name);
}
global.loadEvents = function() {
return appRequire('events');
}
global.loadModules = function(name) {
return appRequire('modules/'+name);
}
// Create a server with a host and port
const server = new Hapi.Server();
server.realm.modifiers.route.prefix = '/api'
server.connection({
host: process.env.HOST,
port: process.env.PORT,
routes: { cors: true }
});
// Add the route
server.register(loadModules('index')());
// Start the server
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});