node-http-server – Diff between revs 30 and 31
?pathlinks?
Rev 30 | Rev 31 | |||
---|---|---|---|---|
Line 14... | Line 14... | |||
14 | const winston = require('winston'); |
14 | const winston = require('winston'); |
|
15 | const yargs = require('yargs'); |
15 | const yargs = require('yargs'); |
|
16 | const dns = require('dns'); |
16 | const dns = require('dns'); |
|
Line 17... | Line 17... | |||
17 | |
17 | |
|
18 | // Local imports. |
18 | // Local imports. |
|
19 | const handler = require( |
19 | const Handler = require( |
|
20 | path |
20 | path |
|
21 | .resolve( |
21 | .resolve( |
|
22 | path.dirname(require.main.filename), |
22 | path.dirname(require.main.filename), |
|
23 | 'src', |
23 | 'src', |
|
Line 92... | Line 92... | |||
92 | |
92 | |
|
93 | // Start HTTP server. |
93 | // Start HTTP server. |
|
94 | http.createServer( |
94 | http.createServer( |
|
95 | // authentication, |
95 | // authentication, |
|
96 | (request, response) => |
96 | (request, response) => |
|
97 | handler.process(config, request, response, root, (logging, result) => { |
- | ||
98 | |
97 | new Handler().process(config, request, response, root) |
|
99 | // Log the message by severity. |
98 | .on('log', (data) => { |
|
100 | log.log(logging.severity, logging.message); |
- | ||
101 | |
- | ||
102 | // If no result is to be processed, then terminate the request. |
99 | log.log(data.severity, data.message); |
|
103 | if (typeof result === 'undefined' || result === null) |
100 | }) |
|
104 | return; |
- | ||
105 | |
101 | .on('data', (result) => { |
|
106 | // Set the response status. |
102 | // Set the response status. |
|
107 | response.status = result.status; |
103 | response.status = result.status; |
|
108 | // Set the content type and send the data. |
104 | // Set the content type and send the data. |
|
109 | response.setHeader('Content-Type', result.type); |
105 | response.setHeader('Content-Type', result.type); |
|
Line 134... | Line 130... | |||
134 | { |
130 | { |
|
135 | key: certificates.privateKey, |
131 | key: certificates.privateKey, |
|
136 | cert: certificates.certificate, |
132 | cert: certificates.certificate, |
|
137 | }, |
133 | }, |
|
138 | (request, response) => |
134 | (request, response) => |
|
139 | handler.process(config, request, response, root, (result) => { |
135 | new Handler().process(config, request, response, root) |
|
140 | // Log the message by severity. |
136 | .on('log', (data) => { |
|
141 | log.log(logging.severity, logging.message); |
137 | log.log(data.severity, data.message); |
|
142 | |
- | ||
143 | // If no result is to be processed, then terminate the request. |
- | ||
144 | if (typeof result === 'undefined' || result === null) |
138 | }) |
|
145 | return; |
139 | .on('data', (result) => { |
|
146 | |
- | ||
147 | // Set the response status. |
140 | // Set the response status. |
|
148 | response.status = result.status; |
141 | response.status = result.status; |
|
149 | // Set the content type and send the data. |
142 | // Set the content type and send the data. |
|
150 | response.setHeader('Content-Type', result.type); |
143 | response.setHeader('Content-Type', result.type); |
|
151 | result.data |
144 | result.data |