/server.js |
@@ -14,6 +14,7 @@ |
const winston = require('winston'); |
const yargs = require('yargs'); |
const dns = require('dns'); |
const HttpCache = require("http-cache"); |
|
// Local imports. |
const Handler = require( |
@@ -90,21 +91,26 @@ |
process.exit(1); |
} |
|
// Create server-side cache. |
const httpcache = new HttpCache(); |
|
// Start HTTP server. |
http.createServer( |
// authentication, |
(request, response) => |
new Handler().process(config, request, response, root) |
.on('log', (data) => { |
log.log(data.severity, data.message); |
httpcache(request, response, () => { |
new Handler().process(config, request, response, root) |
.on('log', (data) => { |
log.log(data.severity, data.message); |
}) |
.on('data', (result) => { |
response.setHeader('Content-Type', result.type); |
response.writeHead(result.status); |
result.data |
.on('readable', () => result.data.pipe(response)) |
.on('end', () => response.end()); |
}); |
}) |
.on('data', (result) => { |
response.setHeader('Content-Type', result.type); |
response.writeHead(result.status); |
result.data |
.on('readable', () => result.data.pipe(response)) |
.on('end', () => response.end()); |
}) |
).listen(config.net.port, config.net.address, () => { |
log.info('HTTP Server accessible at: http://' + |
config.net.address + |