-
Notifications
You must be signed in to change notification settings - Fork 48
/
index.js
64 lines (52 loc) · 1.33 KB
/
index.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
/**
* Serves static assets and proxies /_api requests to couchdb
*/
var Hapi = require('hapi')
var hapi_plugins = require('./hapi_plugins')
module.exports = function () {
return function (env_config, callback) {
var options = {
connections: {
routes: {
cors: {override: false},
payload: {maxBytes: 1048576 * 10} // 10 MB
}
}
}
if (env_config.debug) {
options.debug = {
log: ['error'],
request: ['error']
}
}
var server = new Hapi.Server(options)
env_config.hooks.runStatic('server.pack.pre', [server])
server.connection({
port: env_config.www_port,
labels: ['web']
})
server.connection({
port: env_config.admin_port,
labels: ['admin']
})
// register plugins against the server pack
hapi_plugins.forEach(function (plugin) {
server.register({
register: plugin,
options: {
app: env_config
}
}, function (error) {
if (error) {
console.error('Failed to load a plugin:', error)
}
})
})
env_config.hooks.runStatic('server.pack.post', [server])
server.start(function () {
console.log('WWW: ', env_config.www_link)
console.log('Admin: ', env_config.admin_link)
return callback()
})
}
}