// To use it create some files under `mocks/` // e.g. `server/mocks/ember-hamsters.js` // // module.exports = function(app) { // app.get('/ember-hamsters', function(req, res) { // res.send('hello'); // }); // }; // http://stackoverflow.com/q/11001817 var allowCrossDomain = function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With'); // intercept OPTIONS method if ('OPTIONS' == req.method) { res.sendStatus(200); } else { next(); } }; module.exports = function(app) { var globSync = require('glob').sync; var mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require); var proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require); // Log proxy requests var morgan = require('morgan'); app.use(morgan('dev')); app.use(allowCrossDomain); // Parse json var bodyParser = require('body-parser'); app.use(bodyParser.json()); mocks.forEach(function(route) { route(app); }); proxies.forEach(function(route) { route(app); }); };