mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-19 00:04:51 +00:00
Refactor server route handling to handle default documents properly
This commit is contained in:
parent
a8770d7645
commit
5fcff1f1a3
@ -16,7 +16,7 @@ var zlib = require("zlib");
|
|||||||
|
|
||||||
exports.method = "GET";
|
exports.method = "GET";
|
||||||
|
|
||||||
exports.path = /^\/$/;
|
exports.path = /^\/index.html$/;
|
||||||
|
|
||||||
exports.handler = function(request,response,state) {
|
exports.handler = function(request,response,state) {
|
||||||
var acceptEncoding = request.headers["accept-encoding"];
|
var acceptEncoding = request.headers["accept-encoding"];
|
||||||
|
@ -127,11 +127,11 @@ Server.prototype.addAuthenticator = function(AuthenticatorClass) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype.findMatchingRoute = function(request,state) {
|
Server.prototype.findMatchingRoute = function(request,state,options) {
|
||||||
|
options = options || {};
|
||||||
for(var t=0; t<this.routes.length; t++) {
|
for(var t=0; t<this.routes.length; t++) {
|
||||||
var potentialRoute = this.routes[t],
|
var potentialRoute = this.routes[t],
|
||||||
pathRegExp = potentialRoute.path,
|
pathname = options.pathname || state.urlInfo.pathname,
|
||||||
pathname = state.urlInfo.pathname,
|
|
||||||
match;
|
match;
|
||||||
if(state.pathPrefix) {
|
if(state.pathPrefix) {
|
||||||
if(pathname.substr(0,state.pathPrefix.length) === state.pathPrefix) {
|
if(pathname.substr(0,state.pathPrefix.length) === state.pathPrefix) {
|
||||||
@ -207,6 +207,15 @@ Server.prototype.requestHandler = function(request,response,options) {
|
|||||||
}
|
}
|
||||||
// Find the route that matches this path
|
// Find the route that matches this path
|
||||||
var route = self.findMatchingRoute(request,state);
|
var route = self.findMatchingRoute(request,state);
|
||||||
|
if(!route) {
|
||||||
|
// Try with the default document
|
||||||
|
var defaultDocumentPathname = state.urlInfo.pathname;
|
||||||
|
if(defaultDocumentPathname.substr(-1) !== "/") {
|
||||||
|
defaultDocumentPathname = defaultDocumentPathname + "/";
|
||||||
|
}
|
||||||
|
defaultDocumentPathname = defaultDocumentPathname + "index.html";
|
||||||
|
route = self.findMatchingRoute(request,state,{pathname: defaultDocumentPathname});
|
||||||
|
}
|
||||||
// Optionally output debug info
|
// Optionally output debug info
|
||||||
if(self.get("debug-level") !== "none") {
|
if(self.get("debug-level") !== "none") {
|
||||||
console.log("Request path:",JSON.stringify(state.urlInfo));
|
console.log("Request path:",JSON.stringify(state.urlInfo));
|
||||||
|
Loading…
Reference in New Issue
Block a user