Skip to content

Instantly share code, notes, and snippets.

@mattboon
Created June 3, 2015 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattboon/43efe4b92d120389045e to your computer and use it in GitHub Desktop.
Save mattboon/43efe4b92d120389045e to your computer and use it in GitHub Desktop.
middleware.js
'use strict';
var glob = require('glob');
var objectAssign = require('react/lib/Object.assign');
var defaults = {
folder: './app/node_modules/components/',
extension: '.jsx'
};
module.exports = function(opts) {
var options = objectAssign({}, defaults, opts);
return function(req, res, next) {
var files = glob.sync(options.folder + '**/*' + options.extension);
var components = files.map(function(file) {
var path = file.replace('/index' + options.extension, '');
var slug = path.replace(options.folder, '');
var component = {};
component.slug = slug;
component.path = path;
return component;
});
res.locals.components = components;
next();
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment