Allow index.html in root

This commit is contained in:
Bryan Ashby 2017-10-29 20:04:10 -06:00
parent 2efc522d68
commit 4b0ef85432
1 changed files with 16 additions and 0 deletions

View File

@ -158,6 +158,11 @@ exports.getModule = class WebServerModule extends ServerModule {
routeRequest(req, resp) { routeRequest(req, resp) {
const route = _.find(this.routes, r => r.matchesRequest(req) ); const route = _.find(this.routes, r => r.matchesRequest(req) );
if(!route && '/' === req.url) {
return this.routeIndex(req, resp);
}
return route ? route.handler(req, resp) : this.accessDenied(resp); return route ? route.handler(req, resp) : this.accessDenied(resp);
} }
@ -196,9 +201,20 @@ exports.getModule = class WebServerModule extends ServerModule {
return this.respondWithError(resp, 404, 'File not found.', 'File Not Found'); return this.respondWithError(resp, 404, 'File not found.', 'File Not Found');
} }
routeIndex(req, resp) {
const filePath = paths.join(Config.contentServers.web.staticRoot, 'index.html');
return this.returnStaticPage(filePath, resp);
}
routeStaticFile(req, resp) { routeStaticFile(req, resp) {
const fileName = req.url.substr(req.url.indexOf('/', 1)); const fileName = req.url.substr(req.url.indexOf('/', 1));
const filePath = paths.join(Config.contentServers.web.staticRoot, fileName); const filePath = paths.join(Config.contentServers.web.staticRoot, fileName);
return this.returnStaticPage(filePath, resp);
}
returnStaticPage(filePath, resp) {
const self = this; const self = this;
fs.stat(filePath, (err, stats) => { fs.stat(filePath, (err, stats) => {