aboutsummaryrefslogtreecommitdiff
path: root/javascript/server/index.js
blob: eadf932962fc35249d6d072bf56d4a7111e33109 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* eslint-env node */
'use strict';

//https://discuss.emberjs.com/t/how-to-disable-http-mock-server-within-environment-config-file/6660/9

//To use http mocks from server/mocks for testing:
//ember server
//To use real server:
//ember server --proxy=http://localhost:8080/

function usingProxy() {
  return !!process.argv.filter(function (arg) {
    return arg.indexOf('--proxy') === 0;
  }).length;
}

module.exports = function(app) {
  if (usingProxy()) { return; }
  
  const globSync   = require('glob').sync;
  const mocks      = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require);
  const proxies    = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require);

  // Log proxy requests
  const morgan = require('morgan');
  app.use(morgan('dev'));

  mocks.forEach(route => route(app));
  proxies.forEach(route => route(app));
};