Commit 62609cbc authored by Ray Schamp's avatar Ray Schamp

Collapse by beginning all routes with a common `^`

parent eba654c4
...@@ -18,9 +18,9 @@ var fastly = require('./lib/fastly-extended')(process.env.FASTLY_API_KEY, FASTLY ...@@ -18,9 +18,9 @@ var fastly = require('./lib/fastly-extended')(process.env.FASTLY_API_KEY, FASTLY
var extraAppRoutes = [ var extraAppRoutes = [
// Homepage with querystring. // Homepage with querystring.
// TODO: Should this be added for every route? // TODO: Should this be added for every route?
'^/\\?', '/\\?',
// View html // View html
'^/[^\/]*\.html$' '/[^\/]*\.html$'
]; ];
/* /*
...@@ -35,7 +35,7 @@ var getStaticPaths = function (pathToStatic) { ...@@ -35,7 +35,7 @@ var getStaticPaths = function (pathToStatic) {
}).map(function (pathName) { }).map(function (pathName) {
// Reduce absolute path to relative paths like '/js' // Reduce absolute path to relative paths like '/js'
var base = path.dirname(path.resolve(__dirname, pathToStatic)); var base = path.dirname(path.resolve(__dirname, pathToStatic));
return '^' + pathName.replace(base, '') + (path.extname(pathName) ? '' : '/'); return pathName.replace(base, '') + (path.extname(pathName) ? '' : '/');
}); });
}; };
...@@ -66,9 +66,9 @@ var expressPatternToRegex = function (pattern) { ...@@ -66,9 +66,9 @@ var expressPatternToRegex = function (pattern) {
* string suitable for a Fastly condition * string suitable for a Fastly condition
*/ */
var pathsToCondition = function (paths) { var pathsToCondition = function (paths) {
return 'req.url~"' + paths.reduce(function (conditionString, pattern) { return 'req.url~^("' + paths.reduce(function (conditionString, pattern) {
return conditionString + (conditionString ? '|' : '') + pattern; return conditionString + (conditionString ? '|' : '') + pattern;
}, '') + '"'; }, '') + ')"';
}; };
/* /*
......
...@@ -2,39 +2,42 @@ ...@@ -2,39 +2,42 @@
{ {
"name": "splash", "name": "splash",
"pattern": "^/?$", "pattern": "^/?$",
"routeAlias": "/?$",
"view": "splash/splash", "view": "splash/splash",
"title": "Imagine, Program, Share" "title": "Imagine, Program, Share"
}, },
{ {
"name": "about", "name": "about",
"pattern": "^/about/?$", "pattern": "^/about/?$",
"routeAlias": "/about/?$",
"view": "about/about", "view": "about/about",
"title": "About" "title": "About"
}, },
{ {
"name": "guidelines", "name": "guidelines",
"pattern": "^/community_guidelines/?$", "pattern": "^/community_guidelines/?$",
"routeAlias": "/community_guidelines/?$",
"view": "guidelines/guidelines", "view": "guidelines/guidelines",
"title": "Scratch Community Guidelines" "title": "Scratch Community Guidelines"
}, },
{ {
"name": "student-complete-registration", "name": "student-complete-registration",
"pattern": "^/classes/complete_registration", "pattern": "^/classes/complete_registration",
"routeAlias": "^/classes/(complete_registration|.+/register/.+)", "routeAlias": "/classes/(complete_registration|.+/register/.+)",
"view": "studentcompleteregistration/studentcompleteregistration", "view": "studentcompleteregistration/studentcompleteregistration",
"title": "Complete your Registration" "title": "Complete your Registration"
}, },
{ {
"name": "student-registration", "name": "student-registration",
"pattern": "^/classes/:id/register/:token", "pattern": "^/classes/:id/register/:token",
"routeAlias": "^/classes/(complete_registration|.+/register/.+)", "routeAlias": "/classes/(complete_registration|.+/register/.+)",
"view": "studentregistration/studentregistration", "view": "studentregistration/studentregistration",
"title": "Class Registration" "title": "Class Registration"
}, },
{ {
"name": "conference-index", "name": "conference-index",
"pattern": "^/conference/?$", "pattern": "^/conference/?$",
"routeAlias": "^/conference(?!/201[4-5])", "routeAlias": "/conference(?!/201[4-5])",
"view": "conference/index/index", "view": "conference/index/index",
"title": "Scratch Conference", "title": "Scratch Conference",
"viewportWidth": "device-width" "viewportWidth": "device-width"
...@@ -42,7 +45,7 @@ ...@@ -42,7 +45,7 @@
{ {
"name": "conference-plan", "name": "conference-plan",
"pattern": "^/conference/plan/?$", "pattern": "^/conference/plan/?$",
"routeAlias": "^/conference(?!/201[4-5])", "routeAlias": "/conference(?!/201[4-5])",
"view": "conference/plan/plan", "view": "conference/plan/plan",
"title": "Plan Your Visit", "title": "Plan Your Visit",
"viewportWidth": "device-width" "viewportWidth": "device-width"
...@@ -50,7 +53,7 @@ ...@@ -50,7 +53,7 @@
{ {
"name": "conference-expectations", "name": "conference-expectations",
"pattern": "^/conference/expect/?$", "pattern": "^/conference/expect/?$",
"routeAlias": "^/conference(?!/201[4-5])", "routeAlias": "/conference(?!/201[4-5])",
"view": "conference/expect/expect", "view": "conference/expect/expect",
"title": "What to Expect", "title": "What to Expect",
"viewportWidth": "device-width" "viewportWidth": "device-width"
...@@ -58,7 +61,7 @@ ...@@ -58,7 +61,7 @@
{ {
"name": "conference-schedule", "name": "conference-schedule",
"pattern": "^/conference/schedule/?$", "pattern": "^/conference/schedule/?$",
"routeAlias": "^/conference(?!/201[4-5])", "routeAlias": "/conference(?!/201[4-5])",
"view": "conference/schedule/schedule", "view": "conference/schedule/schedule",
"title": "Conference Schedule", "title": "Conference Schedule",
"viewportWidth": "device-width" "viewportWidth": "device-width"
...@@ -66,7 +69,7 @@ ...@@ -66,7 +69,7 @@
{ {
"name": "conference-details", "name": "conference-details",
"pattern": "^/conference/:id/details/?$", "pattern": "^/conference/:id/details/?$",
"routeAlias": "^/conference(?!/201[4-5])", "routeAlias": "/conference(?!/201[4-5])",
"view": "conference/details/details", "view": "conference/details/details",
"title": "Event Details", "title": "Event Details",
"viewportWidth": "device-width" "viewportWidth": "device-width"
...@@ -74,30 +77,35 @@ ...@@ -74,30 +77,35 @@
{ {
"name": "developers", "name": "developers",
"pattern": "^/developers/?$", "pattern": "^/developers/?$",
"routeAlias": "/developers/?$",
"view": "developers/developers", "view": "developers/developers",
"title": "Developers" "title": "Developers"
}, },
{ {
"name": "dmca", "name": "dmca",
"pattern": "^/DMCA/?$", "pattern": "^/DMCA/?$",
"routeAlias": "/DMCA/?$",
"view": "dmca/dmca", "view": "dmca/dmca",
"title": "DMCA" "title": "DMCA"
}, },
{ {
"name": "educator-landing", "name": "educator-landing",
"pattern": "^/educators/?$", "pattern": "^/educators/?$",
"routeAlias": "/educators(?:/(faq|register|waiting))?/?$",
"view": "teachers/landing/landing", "view": "teachers/landing/landing",
"title": "Educators" "title": "Educators"
}, },
{ {
"name": "teacher-faq", "name": "teacher-faq",
"pattern": "^/educators/faq/?$", "pattern": "^/educators/faq/?$",
"routeAlias": "/educators(?:/(faq|register|waiting))?/?$",
"view": "teachers/faq/faq", "view": "teachers/faq/faq",
"title": "Teacher Accounts FAQ" "title": "Teacher Accounts FAQ"
}, },
{ {
"name": "teacherregistration", "name": "teacherregistration",
"pattern": "^/educators/register$", "pattern": "^/educators/register$",
"routeAlias": "/educators(?:/(faq|register|waiting))?/?$",
"view": "teacherregistration/teacherregistration", "view": "teacherregistration/teacherregistration",
"title": "Teacher Registration", "title": "Teacher Registration",
"viewportWidth": "device-width" "viewportWidth": "device-width"
...@@ -105,98 +113,109 @@ ...@@ -105,98 +113,109 @@
{ {
"name": "teacherwaitingroom", "name": "teacherwaitingroom",
"pattern": "^/educators/waiting", "pattern": "^/educators/waiting",
"routeAlias": "/educators(?:/(faq|register|waiting))?/?$",
"view": "teacherwaitingroom/teacherwaitingroom", "view": "teacherwaitingroom/teacherwaitingroom",
"title": "Thank you for requesting a Scratch Teacher Account" "title": "Thank you for requesting a Scratch Teacher Account"
}, },
{ {
"name": "explore", "name": "explore",
"pattern": "^/explore/:projects/:all/?$", "pattern": "^/explore/:projects/:all/?$",
"routeAlias": "^/explore(?!/ajax)", "routeAlias": "/explore(?!/ajax)",
"view": "explore/explore", "view": "explore/explore",
"title": "Explore" "title": "Explore"
}, },
{ {
"name": "hoc", "name": "hoc",
"pattern": "^/hoc/?$", "pattern": "^/hoc/?$",
"routeAlias": "/hoc/?$",
"view": "hoc/hoc", "view": "hoc/hoc",
"title": "Hour of Code" "title": "Hour of Code"
}, },
{ {
"name": "cards", "name": "cards",
"pattern": "^/info/cards/?$", "pattern": "^/info/cards/?$",
"routeAlias": "/info/(cards|communityblocks-interviews|credits|faq)/?$",
"view": "cards/cards", "view": "cards/cards",
"title": "Cards" "title": "Cards"
}, },
{ {
"name": "communityblocks-interviews", "name": "communityblocks-interviews",
"pattern": "^/info/communityblocks-interviews/?$", "pattern": "^/info/communityblocks-interviews/?$",
"routeAlias": "/info/(cards|communityblocks-interviews|credits|faq|donate)/?$",
"view": "communityblocks-interviews/communityblocks-interviews", "view": "communityblocks-interviews/communityblocks-interviews",
"title": "Community Blocks Beta Tester Interviews" "title": "Community Blocks Beta Tester Interviews"
}, },
{ {
"name": "credits", "name": "credits",
"pattern": "^/info/credits/?$", "pattern": "^/info/credits/?$",
"routeAlias": "/info/(cards|communityblocks-interviews|credits|faq)/?$",
"view": "credits/credits", "view": "credits/credits",
"title": "Credits" "title": "Credits"
}, },
{ {
"name": "faq", "name": "faq",
"pattern": "^/info/faq/?$", "pattern": "^/info/faq/?$",
"routeAlias": "/info/(cards|communityblocks-interviews|credits|faq)/?$",
"view": "faq/faq", "view": "faq/faq",
"title": "FAQ" "title": "FAQ"
}, },
{ {
"name": "jobs", "name": "jobs",
"pattern": "^/jobs/?$", "pattern": "^/jobs/?$",
"routeAlias": "/jobs/?$",
"view": "jobs/jobs", "view": "jobs/jobs",
"title": "Jobs" "title": "Jobs"
}, },
{ {
"name": "privacypolicy", "name": "privacypolicy",
"pattern": "^/privacy_policy/?$", "pattern": "^/privacy_policy/?$",
"routeAlias": "/privacy_policy/?$",
"view": "privacypolicy/privacypolicy", "view": "privacypolicy/privacypolicy",
"title": "Privacy Policy" "title": "Privacy Policy"
}, },
{ {
"name": "search", "name": "search",
"pattern": "^/search/:projects?$/?$", "pattern": "^/search/:projects?$/?$",
"routeAlias": "^/search", "routeAlias": "/search",
"view": "search/search", "view": "search/search",
"title": "Search" "title": "Search"
}, },
{ {
"name": "terms", "name": "terms",
"pattern": "^/terms_of_use/?$", "pattern": "^/terms_of_use/?$",
"routeAlias": "/terms_of_use/?$",
"view": "terms/terms", "view": "terms/terms",
"title": "Scratch Terms of Use" "title": "Scratch Terms of Use"
}, },
{ {
"name": "wedo2", "name": "wedo2",
"pattern": "^/wedo/?$", "pattern": "^/wedo/?$",
"routeAlias": "/wedo/?$",
"view": "wedo2/wedo2", "view": "wedo2/wedo2",
"title": "LEGO WeDo 2.0" "title": "LEGO WeDo 2.0"
}, },
{ {
"name": "donate", "name": "donate",
"pattern": "^/info/donate/?", "pattern": "^/info/donate/?",
"routeAlias": "/info/(cards|communityblocks-interviews|credits|faq|donate)/?$",
"redirect": "https://secure.donationpay.org/scratchfoundation/" "redirect": "https://secure.donationpay.org/scratchfoundation/"
}, },
{ {
"name": "explore-redirect", "name": "explore-redirect",
"pattern": "^/explore/?$", "pattern": "^/explore/?$",
"routeAlias": "^/explore(?!/ajax)", "routeAlias": "/explore(?!/ajax)",
"redirect": "/explore/projects/all" "redirect": "/explore/projects/all"
}, },
{ {
"name": "explore-projects-redirect", "name": "explore-projects-redirect",
"pattern": "^/explore/projects/?$", "pattern": "^/explore/projects/?$",
"routeAlias": "^/explore(?!/ajax)", "routeAlias": "/explore(?!/ajax)",
"redirect": "/explore/projects/all" "redirect": "/explore/projects/all"
}, },
{ {
"name": "explore-studios-redirect", "name": "explore-studios-redirect",
"pattern": "^/explore/studios/?$", "pattern": "^/explore/studios/?$",
"routeAlias": "^/explore(?!/ajax)", "routeAlias": "/explore(?!/ajax)",
"redirect": "/explore/studios/all" "redirect": "/explore/studios/all"
} }
] ]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment