Skip to content

Instantly share code, notes, and snippets.

@ChitaGideon
Last active August 29, 2015 14:18
Show Gist options
  • Save ChitaGideon/356e063f1e413d6424ad to your computer and use it in GitHub Desktop.
Save ChitaGideon/356e063f1e413d6424ad to your computer and use it in GitHub Desktop.
find all route path in krakenjs
app.on 'middleware:after:router',(eventargs)->
routes = []
app._router.stack.forEach (route)->
getPath = (route)->
route.path ||route.route?.path || route.regexp.toString().match(/[\/\w]+/g)[1..-4].join("")
recurPath = (route,head,arr)->
routeStr = getPath(route)
if route.handle?.stack
route.handle.stack.forEach (subRoute)->
recurPath(subRoute,head+routeStr,arr)
else if route.route?.stack
route.route.stack.forEach (subRoute)->
recurPath(subRoute,head+routeStr,arr)
else
o = {}
o[route.method] = head+routeStr
arr.push o
if(route.name == "router")
recurPath route,"",routes
debug "routes ",routes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment