node-http-server – Diff between revs 36 and 37
?pathlinks?
Rev 36 | Rev 37 | |||
---|---|---|---|---|
Line 95... | Line 95... | |||
95 | const httpcache = new HttpCache(); |
95 | const httpcache = new HttpCache(); |
|
Line 96... | Line 96... | |||
96 | |
96 | |
|
97 | // Start HTTP server. |
97 | // Start HTTP server. |
|
98 | http.createServer( |
98 | http.createServer( |
|
99 | // authentication, |
99 | // authentication, |
|
- | 100 | (request, response) => { |
||
- | 101 | // Configuration path requested, so send the server configuration if allowed. |
||
- | 102 | if(config.configuration.enable === true && |
||
- | 103 | url.parse(request.url, true).path === |
||
- | 104 | config.configuration.path) { |
||
- | 105 | const address = request.socket.address(); |
||
- | 106 | log.info('HTTP Server configuration requested by: ' + |
||
- | 107 | address.address + ':' + |
||
- | 108 | address.port |
||
- | 109 | ); |
||
- | 110 | response.setHeader('Content-Type', 'application/json'); |
||
- | 111 | response.end(JSON.stringify(config)); |
||
- | 112 | return; |
||
- | 113 | } |
||
- | 114 | |
||
100 | (request, response) => |
115 | // Process and cache the resource. |
|
101 | httpcache(request, response, () => { |
116 | httpcache(request, response, () => { |
|
102 | new Handler().process(config, request, response, root) |
117 | new Handler().process(config, request, response, root) |
|
103 | .on('log', (data) => { |
118 | .on('log', (data) => { |
|
104 | log.log(data.severity, data.message); |
119 | log.log(data.severity, data.message); |
|
105 | }) |
120 | }) |
|
106 | .on('data', (result) => { |
121 | .on('data', (result) => { |
|
107 | response.setHeader('Content-Type', result.type); |
122 | response.setHeader('Content-Type', result.type); |
|
108 | response.writeHead(result.status); |
123 | response.writeHead(result.status); |
|
109 | result.data |
124 | result.data |
|
110 | .on('readable', () => result.data.pipe(response)) |
125 | .on('readable', () => result.data.pipe(response)) |
|
111 | .on('end', () => response.end()); |
126 | .on('end', () => response.end()); |
|
- | 127 | }); |
||
112 | }); |
128 | }); |
|
113 | }) |
129 | } |
|
114 | ).listen(config.net.port, config.net.address, () => { |
130 | ).listen(config.net.port, config.net.address, () => { |
|
115 | log.info('HTTP Server accessible at: http://' + |
131 | log.info('HTTP Server accessible at: http://' + |
|
116 | config.net.address + |
132 | config.net.address + |
|
117 | ':' + |
133 | ':' + |
|
Line 133... | Line 149... | |||
133 | // authentication, |
149 | // authentication, |
|
134 | { |
150 | { |
|
135 | key: certificates.privateKey, |
151 | key: certificates.privateKey, |
|
136 | cert: certificates.certificate, |
152 | cert: certificates.certificate, |
|
137 | }, |
153 | }, |
|
138 | (request, response) => |
154 | (request, response) => { |
|
- | 155 | |
||
- | 156 | // Configuration path requested, so send the server configuration if allowed. |
||
- | 157 | if(config.configuration.enable === true && |
||
- | 158 | url.parse(request.url, true).path === |
||
- | 159 | config.configuration.path) { |
||
- | 160 | const address = request.socket.address(); |
||
- | 161 | log.info('HTTP Server configuration requested by: ' + |
||
- | 162 | address.address + ':' + |
||
- | 163 | address.port |
||
- | 164 | ); |
||
- | 165 | response.setHeader('Content-Type', 'application/json'); |
||
- | 166 | response.end(JSON.stringify(config)); |
||
- | 167 | return; |
||
- | 168 | } |
||
- | 169 | |
||
- | 170 | httpcache(request, response, () => { |
||
139 | new Handler().process(config, request, response, root) |
171 | new Handler().process(config, request, response, root) |
|
140 | .on('log', (data) => { |
172 | .on('log', (data) => { |
|
141 | log.log(data.severity, data.message); |
173 | log.log(data.severity, data.message); |
|
142 | }) |
174 | }) |
|
143 | .on('data', (result) => { |
175 | .on('data', (result) => { |
|
144 | response.setHeader('Content-Type', result.type); |
176 | response.setHeader('Content-Type', result.type); |
|
145 | response.writeHead(result.status); |
177 | response.writeHead(result.status); |
|
146 | result.data |
178 | result.data |
|
147 | .on('readable', () => result.data.pipe(response)) |
179 | .on('readable', () => result.data.pipe(response)) |
|
148 | .on('end', () => response.end()); |
180 | .on('end', () => response.end()); |
|
- | 181 | }); |
||
- | 182 | }); |
||
149 | }) |
183 | } |
|
150 | ).listen(config.ssl.port, config.ssl.address, () => { |
184 | ).listen(config.ssl.port, config.ssl.address, () => { |
|
151 | log.info('HTTPs Server accessible at: https://' + |
185 | log.info('HTTPs Server accessible at: https://' + |
|
152 | config.ssl.address + |
186 | config.ssl.address + |
|
153 | ':' + |
187 | ':' + |
|
154 | config.ssl.port + |
188 | config.ssl.port + |