-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
44 lines (32 loc) · 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
"use strict"
GLOBAL.rootPath = __dirname;
var Hapi = require("Hapi"),
config = require("./server/config/config"),
mongoose = require("mongoose"),
options = require("./server/config/options");
var server = Hapi.createServer(config.server.host, config.server.port, options);
mongoose.connect("mongodb://" + config.mongodb.host + "/" + config.mongodb.db);
server.pack.register({
plugin: require("hapi-auth-cookie")
}, function (err) {
err ? console.log(err) : "";
server.auth.strategy('session', 'cookie',
{
password: config.secret,
redirectTo: "/",
ttl: 1000 * 3600,
isSecure: false
}
);
require("./server/config/listener")(server);
require("./server/routes")(server);
server.start(function () {
console.log('Server started at: ' + server.info.uri);
mongoose.connection.on("open", function () {
});
mongoose.connection.on("error", function () {
throw new Error("Cannot connect to mongodb");
server.stop();
});
});
});