Matteo Scandolo | 4eb4ccb | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | |-------------------------------------------------------------------------- |
| 4 | | Browser-sync config file |
| 5 | |-------------------------------------------------------------------------- |
| 6 | | |
| 7 | | For up-to-date information about the options: |
| 8 | | http://www.browsersync.io/docs/options/ |
| 9 | | |
| 10 | | There are more options than you see here, these are just the ones that are |
| 11 | | set internally. See the website for more info. |
| 12 | | |
| 13 | | |
| 14 | */ |
| 15 | |
| 16 | var httpProxy = require('http-proxy'); |
| 17 | var environment = process.env.NODE_ENV; |
| 18 | |
| 19 | if (environment){ |
Matteo Scandolo | 9fb53f7 | 2016-01-26 11:34:15 -0800 | [diff] [blame] | 20 | var conf = require(`./env/${environment}.js`); |
Matteo Scandolo | 4eb4ccb | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 21 | } |
| 22 | else{ |
Matteo Scandolo | 9fb53f7 | 2016-01-26 11:34:15 -0800 | [diff] [blame] | 23 | var conf = require('./env/default.js') |
Matteo Scandolo | 4eb4ccb | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | var proxy = httpProxy.createProxyServer({ |
Matteo Scandolo | 9fb53f7 | 2016-01-26 11:34:15 -0800 | [diff] [blame] | 27 | target: conf.host || 'http://0.0.0.0:9999' |
Matteo Scandolo | 4eb4ccb | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 28 | }); |
| 29 | |
| 30 | proxy.on('error', function(error, req, res) { |
Matteo Scandolo | 9fb53f7 | 2016-01-26 11:34:15 -0800 | [diff] [blame] | 31 | res.writeHead(500, { |
| 32 | 'Content-Type': 'text/plain' |
| 33 | }); |
| 34 | console.error('[Proxy]', error); |
Matteo Scandolo | 4eb4ccb | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 35 | }); |
| 36 | |
| 37 | module.exports = { |
Matteo Scandolo | 9fb53f7 | 2016-01-26 11:34:15 -0800 | [diff] [blame] | 38 | "files": [ |
| 39 | './src/**/*' |
| 40 | ], |
| 41 | "server": { |
| 42 | baseDir: './src', |
Matteo Scandolo | c603650 | 2016-01-26 15:17:10 -0800 | [diff] [blame] | 43 | routes: { |
| 44 | '/rs/dashboard': './mocks/dashboard.json', |
| 45 | '/rs/bundle': './mocks/bundle.json', |
| 46 | '/rs/users': './mocks/users.json' |
| 47 | }, |
Matteo Scandolo | 9fb53f7 | 2016-01-26 11:34:15 -0800 | [diff] [blame] | 48 | middleware: function(req, res, next){ |
| 49 | if( |
| 50 | req.url.indexOf('/xos/') !== -1 || |
| 51 | req.url.indexOf('/xoslib/') !== -1 || |
Matteo Scandolo | c603650 | 2016-01-26 15:17:10 -0800 | [diff] [blame] | 52 | req.url.indexOf('/hpcapi/') !== -1 |
Matteo Scandolo | 9fb53f7 | 2016-01-26 11:34:15 -0800 | [diff] [blame] | 53 | ){ |
Matteo Scandolo | 61f05f5 | 2016-01-28 09:41:01 -0800 | [diff] [blame] | 54 | if(req.headers['X-CSRFToken']){ |
| 55 | req.headers['x-csrftoken'] = req.headers['x-csrftoken']; |
| 56 | } |
Matteo Scandolo | 9fb53f7 | 2016-01-26 11:34:15 -0800 | [diff] [blame] | 57 | proxy.web(req, res); |
| 58 | } |
| 59 | else{ |
| 60 | next(); |
| 61 | } |
| 62 | } |
| 63 | }, |
| 64 | "port": 3000, |
| 65 | "open": "local" |
Matteo Scandolo | 4eb4ccb | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 66 | }; |