Matteo Scandolo | 7480252 | 2016-02-25 09:19:41 -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){ |
| 20 | var conf = require(`./env/${environment}.js`); |
| 21 | } |
| 22 | else{ |
| 23 | var conf = require('./env/default.js') |
| 24 | } |
| 25 | |
| 26 | var proxy = httpProxy.createProxyServer({ |
| 27 | target: conf.host || 'http://0.0.0.0:9999' |
| 28 | }); |
| 29 | |
| 30 | proxy.on('error', function(error, req, res) { |
Matteo Scandolo | 691bfe4 | 2016-05-10 12:59:53 -0700 | [diff] [blame^] | 31 | console.log('------------------------------------------------------'); |
| 32 | // res.writeHead(500, { |
| 33 | // 'Content-Type': 'text/plain' |
| 34 | // }); |
Matteo Scandolo | 7480252 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 35 | console.error('[Proxy]', error); |
Matteo Scandolo | 691bfe4 | 2016-05-10 12:59:53 -0700 | [diff] [blame^] | 36 | console.log('------------------------------------------------------'); |
Matteo Scandolo | 7480252 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 37 | }); |
| 38 | |
| 39 | module.exports = { |
| 40 | "files": [ |
| 41 | './src/**/*.css', |
| 42 | './src/**/*.js', |
| 43 | './src/**/*.json', |
| 44 | './src/**/*.html', |
| 45 | './src/**/*.jpg', |
| 46 | './src/**/*.png', |
| 47 | './src/**/*.gif' |
| 48 | ], |
| 49 | "server": { |
| 50 | baseDir: './src', |
| 51 | //directory: true, |
| 52 | routes: { |
| 53 | '/rs/dashboard': './mocks/dashboard.json', |
| 54 | '/rs/bundle': './mocks/bundle.json', |
| 55 | '/rs/users': './mocks/users.json' |
| 56 | }, |
| 57 | middleware: function(req, res, next){ |
| 58 | if( |
| 59 | req.url.indexOf('/xos/') !== -1 || |
| 60 | req.url.indexOf('/xoslib/') !== -1 || |
| 61 | req.url.indexOf('/hpcapi/') !== -1 |
| 62 | ){ |
| 63 | if(req.headers['X-CSRFToken']){ |
| 64 | req.headers['x-csrftoken'] = req.headers['x-csrftoken']; |
| 65 | req.headers.cookie = `xoscsrftoken=${req.headers['x-csrftoken']}; xossessionid=${req.headers['sessionid']}`; |
| 66 | } |
Matteo Scandolo | 691bfe4 | 2016-05-10 12:59:53 -0700 | [diff] [blame^] | 67 | console.log(`proxied: ${req.url}`, req.headers['x-csrftoken'], req.headers.cookie); |
Matteo Scandolo | 7480252 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 68 | proxy.web(req, res); |
| 69 | } |
| 70 | else{ |
| 71 | next(); |
| 72 | } |
| 73 | } |
| 74 | }, |
| 75 | "port": 3000, |
| 76 | "open": "local" |
| 77 | }; |