-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
113 lines (82 loc) · 1.91 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// This is the server version to be run standalone
// Dependencies
var Hapi = require('hapi');
// Server Config
var config = require('./server/config');
// Create a server with a host, port, and options
var server = new Hapi.Server();
server.connection({
host: config.host,
port: config.port,
routes: config.hapi.options.routes
});
var registerOpts = [
{
register: require("./index")
}
];
var browserSync;
if(config.env == 'development'){
browserSync = require('browser-sync').create();
//restart the server if js files change
//does not work - it needs to reload at the node level duh
//browserSync.watch("server/**/*.js").on("change", function(){
// server.stop();
// server.start(browserSync.reload);
//});
}
var startSync = function(){
//use browserSync in dev mode
if(config.env == 'development' && !browserSync.active){
browserSync.init({
notify: false,
snippetOptions: {
rule: {
match: '<span id="browser-sync-binding"></span>',
fn: function (snippet) {
return snippet;
}
}
},
proxy: "localhost:3000",
files: [
'public/**/*.{js,css,html}',
'server/views/*.html'
]
});
}
}
var start = function(cb){
// Add good logging
registerOpts.push({
register: require("good"),
options: {
reporters: [{
reporter: require('good-console'),
args: [{
request: '*',
log: '*',
error: '*',
ops: '*'
}]
}]
}
});
server.register(registerOpts, function(err) {
if (err) throw err;
server.start(function() {
console.log("Hapi server started @ " + server.info.uri.replace('0.0.0.0', 'localhost'));
if(cb) {
cb();
}
});
});
}
module.exports = {
server: server,
registerOpts: registerOpts,
start: start
}
if (!module.parent) {
start(startSync);
}