Last active
August 29, 2015 14:14
-
-
Save greenlikeorange/5fa069bc0c2001f9bd84 to your computer and use it in GitHub Desktop.
Set Appbase route root in express3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/', page.index); | |
app.get('/approval', page.approval); | |
app.get('/task', page.task); | |
app.get('/report', page.report); | |
app.get('/admin', page.admin); | |
// Then implement root route path | |
setRootRoute('/appA', app); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cloneRegExp( input, injectPattern ) { | |
var pattern = input.source; | |
pattern.replace(injectPattern.find, injectPattern.replace); | |
var flags = ""; | |
if ( input.global || ( /g/i ).test( injectFlags ) ) | |
flags += "g"; | |
if ( input.ignoreCase || ( /i/i ).test( injectFlags ) ) | |
flags += "i"; | |
if ( input.multiline || ( /m/i ).test( injectFlags ) ) | |
flags += "m"; | |
return( new RegExp( pattern, flags ) ); | |
} | |
function setRootRoute(rootRoute, app){ | |
var routes = app.routes, | |
verb, paths; | |
// Getting as HTTP verbs | |
for(verb in routes){ | |
var paths = rotues[verb], | |
regxSource; | |
for(var i = 0; i < paths.length; i++){ | |
paths[i].path = rootRoute + paths[i].path; | |
paths[i].regexp = cloneRegExp(paths[i].regexp, {find: "^", replace: "^"+rootRoute }); | |
} | |
} | |
return app; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment