-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathserver.js
55 lines (40 loc) · 1.1 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
47
48
49
50
51
52
53
54
55
'use strict';
var Hapi = require('hapi');
var path = require('path');
var settings = require('config');
var routes = require('./routes');
var plugins = require('./plugins');
var models = require('./models');
const internals = {
templatePath: '.'
};
const server = new Hapi.Server({
host:settings.host,
port: settings.port
});
// server.connection({port:settings.port, host:settings.host});
// Export the server to be required elsewhere.
var initDb = function(cb){
var sequelize = models.sequelize;
//Test if we're in a sqlite memory database. we may need to run migrations.
if(sequelize.getDialect()==='sqlite' &&
(!sequelize.options.storage || sequelize.options.storage === ':memory:')){
sequelize.getMigrator({
path: process.cwd() + '/migrations',
}).migrate().success(function(){
// The migrations have been executed!
cb();
});
} else {
cb();
}
};
server.route(routes);
internals.main = async () => {
await server.start();
initDb(()=>{
console.log('Server is running at ' + server.info.uri);
});
}
internals.main();
module.exports = server;