Skip to content

Commit

Permalink
fix: simplfy trail slash removal
Browse files Browse the repository at this point in the history
  • Loading branch information
David Longworth committed May 31, 2017
1 parent 7c1e89d commit 9f1320c
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions dadi/lib/cache/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ Cache.prototype.cachingEnabled = function (req) {
*/
Cache.prototype.getEndpointMatchingRequest = function (req) {
var endpoints = this.server.components
var requestUrl = url.parse(req.url, true).pathname

// strip trailing slash before testing
if (requestUrl !== '/' && requestUrl[requestUrl.length - 1] === '/') {
requestUrl = requestUrl.substring(0, requestUrl.length - 1)
}
var requestUrl = url.parse(req.url, true).pathname.replace(/\/+$/, '')

// get the host key that matches the request's host header
var virtualHosts = config.get('virtualHosts')
Expand All @@ -98,7 +93,7 @@ Cache.prototype.getEndpointMatchingRequest = function (req) {
}) || ''

// check if there is a match in the loaded routes for the current request URL
var endpoint = _.find(endpoints, endpoint => {
return _.find(endpoints, endpoint => {
var paths = _.pluck(endpoint.page.routes, 'path')
return (
_.contains(paths, requestUrl) &&
Expand All @@ -107,9 +102,8 @@ Cache.prototype.getEndpointMatchingRequest = function (req) {
: true)
)
})

return endpoint
}

/**
* Retrieves the page component that best matches the paths loaded in api/index.js
* @param {IncomingMessage} req - the current HTTP request
Expand Down

0 comments on commit 9f1320c

Please sign in to comment.