forked from davidjamesstone/noide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (82 loc) · 2.25 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
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
const Glupe = require('glupe')
const config = require('./config')
const sock = require('./server/file-system-watcher')
const appName = require('./package.json').name
Glupe.compose(__dirname, config, function (err, server) {
if (err) {
throw err
}
const meta = {
title: 'Noide',
description: 'Web based code editor',
keywords: 'code,nodejs,editor,browser',
author: '[email protected]',
favicon: '/public/favicon.ico'
}
const onPostHandler = function (request, reply) {
const response = request.response
if (response.variety === 'view') {
if (!response.source.context) {
response.source.context = {}
}
/*
* Apply page meta data
* to the view context data
*/
var context = response.source.context
context.meta = context.meta || {}
for (var key in meta) {
if (!context.meta[key]) {
context.meta[key] = meta[key]
}
}
}
return reply.continue()
}
const preResponse = function (request, reply) {
var response = request.response
if (response.isBoom) {
// An error was raised during
// processing the request
var statusCode = response.output.statusCode
// In the event of 404
// return the `404` view
// if (statusCode === 404) {
// return reply.view('404').code(statusCode)
// }
request.log('error', {
statusCode: statusCode,
data: response.data,
message: response.message
})
// The return the `500` view
// return reply.view('500').code(statusCode)
}
return reply.continue()
}
server.ext('onPostHandler', onPostHandler)
server.ext('onPreResponse', preResponse)
/*
* Start the server
*/
server.start(function (err) {
var details = {
name: appName,
uri: server.info.uri
}
if (err) {
details.error = err
details.message = 'Failed to start ' + details.name
server.log('error', details)
throw err
} else {
details.config = config
details.message = 'Started ' + details.name
server.log('info', details)
console.info(details.message)
sock(server)
server.subscription('/io')
server.subscription('/io/pids')
}
})
})