Use regex in express patterns to limit scope

This fixes https://github.com/LLK/scratchr2/issues/3798 by using regex in expressjs patterns, and then also parsing those regex patterns for fastly, such that we can limit the scope of the regex created for a specific view
This commit is contained in:
Matthew Taylor 2017-05-18 13:57:49 -04:00
parent 30bd5e435d
commit 87da9f3d8a
2 changed files with 3 additions and 2 deletions

View file

@ -37,7 +37,8 @@ var FastlyConfigMethods = {
* all :arguments become .+? * all :arguments become .+?
*/ */
expressPatternToRegex: function (pattern) { expressPatternToRegex: function (pattern) {
return pattern.replace(/(:[^/]+)/gi, '.+?'); pattern = pattern.replace(/(:\w+)(\([^\)]+\))/gi, '$2');
return pattern.replace(/(:\w+)/gi, '.+?');
}, },
/* /*

View file

@ -127,7 +127,7 @@
}, },
{ {
"name": "explore", "name": "explore",
"pattern": "^/explore/:projects/:all/?$", "pattern": "^/explore/:projects(projects|studios)/:all/?$",
"routeAlias": "/explore(?!/ajax)", "routeAlias": "/explore(?!/ajax)",
"view": "explore/explore", "view": "explore/explore",
"title": "Explore" "title": "Explore"