node-http-server

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 36  →  ?path2? @ 37
/config.js.dist
@@ -81,5 +81,11 @@
address: 'localhost',
// The port that the HTTPs server will be listening on.
port: 8080
},
configuration: {
// Whether to enable sending the server configuration.
enable: true,
// The relative path that must be accessed to retrieve the configuration.
path: '/configuration'
}
}
/server.js
@@ -97,20 +97,36 @@
// Start HTTP server.
http.createServer(
// authentication,
(request, response) =>
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());
});
})
(request, response) => {
// Configuration path requested, so send the server configuration if allowed.
if(config.configuration.enable === true &&
url.parse(request.url, true).path ===
config.configuration.path) {
const address = request.socket.address();
log.info('HTTP Server configuration requested by: ' +
address.address + ':' +
address.port
);
response.setHeader('Content-Type', 'application/json');
response.end(JSON.stringify(config));
return;
}
// Process and cache the resource.
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());
});
});
}
).listen(config.net.port, config.net.address, () => {
log.info('HTTP Server accessible at: http://' +
config.net.address +
@@ -135,18 +151,36 @@
key: certificates.privateKey,
cert: certificates.certificate,
},
(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());
})
(request, response) => {
// Configuration path requested, so send the server configuration if allowed.
if(config.configuration.enable === true &&
url.parse(request.url, true).path ===
config.configuration.path) {
const address = request.socket.address();
log.info('HTTP Server configuration requested by: ' +
address.address + ':' +
address.port
);
response.setHeader('Content-Type', 'application/json');
response.end(JSON.stringify(config));
return;
}
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());
});
});
}
).listen(config.ssl.port, config.ssl.address, () => {
log.info('HTTPs Server accessible at: https://' +
config.ssl.address +
/src/cache.js
@@ -28,6 +28,7 @@
EventEmitter.call(this);
const self = this;
 
// Read the resource and cache or not depending on configuration settings.
fs.stat(resource, (error, stats) => {
var expires = 0;
Object.keys(self.config.site.cache).forEach((key) => {