fluffy

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 2  →  ?path2? @ 3
/server.js
@@ -14,15 +14,15 @@
const winston = require('winston');
const yargs = require('yargs');
const dns = require('dns');
const HttpCache = require("http-cache");
const was = require("was.js");
 
// Local imports.
const Handler = require(
const GET = require(
path
.resolve(
path.dirname(require.main.filename),
'src',
'handler'
'get'
)
);
const certs = require(
@@ -91,18 +91,17 @@
process.exit(1);
}
 
// Create server-side cache.
const httpcache = new HttpCache();
 
// Start HTTP server.
http.createServer(
// authentication,
(request, response) => {
// Grab connecting address.
const address = request.socket.address();
// 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
@@ -112,20 +111,36 @@
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());
});
});
// Switch on HTTP method.
was.lambda.switch(
request.method,
(o) => {
log.info('Unsupported HTTP \'' + request.method + '\' method requested by: ' +
address.address + ':' +
address.port
);
},
(o) => o === 'GET',
(o) => {
// Send the resource.
new GET().process(config, request, response, root)
.on('log', (data) => {
log.log(data.severity, data.message);
})
.on('data', (result) => {
response.writeHead(result.status);
result.data
.on('readable', () => result.data.pipe(response))
.on('end', () => response.end());
});
return true;
},
(o) => o === 'PUT',
(o) => {
// TODO: implement PUT
return true;
}
);
}
).listen(config.net.port, config.net.address, () => {
log.info('HTTP Server accessible at: http://' +
@@ -152,11 +167,13 @@
cert: certificates.certificate,
},
(request, response) => {
// Grab connecting address.
const address = request.socket.address();
// 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
@@ -166,20 +183,37 @@
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());
});
});
// Switch on HTTP method.
was.lambda.switch(
request.method,
(o) => {
log.info('Unsupported HTTP \'' + request.method + '\' method requested by: ' +
address.address + ':' +
address.port
);
},
(o) => o === 'GET',
(o) => {
// Send the resource.
new GET().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());
});
return true;
},
(o) => o === 'PUT',
(o) => {
// TODO: implement PUT
return true;
}
);
}
).listen(config.ssl.port, config.ssl.address, () => {
log.info('HTTPs Server accessible at: https://' +