Created
June 9, 2014 18:23
-
-
Save adamloving/738b9d64031f51ebd5ea to your computer and use it in GitHub Desktop.
Gulp task to show the routes in an express app (similar to rails rake routes).
This file contains 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
var app = require('../server/app.js').create() | |
var gulp = require('gulp'); | |
var task = require('./index'); | |
/* | |
Output all the routes that the app supports | |
*/ | |
gulp.task('routes', function() { | |
var paths = {}; | |
for (method in app.routes) { | |
// there's a slew of methods we don't care about | |
if (-1 == ['get', 'post', 'put', 'delete', 'options'].indexOf(method)) break; | |
var routes = app.routes[method]; | |
for (i in routes) { | |
path = routes[i].path; | |
paths[path] = paths[path] || {}; | |
paths[path].methods = paths[path].methods || []; | |
if (-1 == paths[path].methods.indexOf(method)) | |
paths[path].methods.push(method); | |
} | |
} | |
console.log('Here are the routes the app supports:'); | |
for (path in paths) { | |
console.log(path, paths[path].methods); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment