Skip to content

Instantly share code, notes, and snippets.

@adamloving
Created June 9, 2014 18:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamloving/738b9d64031f51ebd5ea to your computer and use it in GitHub Desktop.
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).
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