Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [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) { |
| 31 | console.log('------------------------------------------------------'); |
| 32 | // res.writeHead(500, { |
| 33 | // 'Content-Type': 'text/plain' |
| 34 | // }); |
| 35 | console.error('[Proxy]', error); |
| 36 | console.log('------------------------------------------------------'); |
| 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( |
Matteo Scandolo | 8cb844e | 2016-06-02 11:39:02 -0700 | [diff] [blame] | 59 | req.url.indexOf('/api/') !== -1 || |
Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 60 | req.url.indexOf('/xos/') !== -1 || |
| 61 | req.url.indexOf('/xoslib/') !== -1 || |
| 62 | req.url.indexOf('/hpcapi/') !== -1 |
| 63 | ){ |
| 64 | if(req.headers['X-CSRFToken']){ |
| 65 | req.headers['x-csrftoken'] = req.headers['x-csrftoken']; |
| 66 | req.headers.cookie = `xoscsrftoken=${req.headers['x-csrftoken']}; xossessionid=${req.headers['sessionid']}`; |
| 67 | } |
Matteo Scandolo | 8cb844e | 2016-06-02 11:39:02 -0700 | [diff] [blame] | 68 | // console.log(`proxied: ${req.url}`, req.headers['x-csrftoken'], req.headers.cookie); |
Matteo Scandolo | bf14f88 | 2016-06-02 10:01:34 -0700 | [diff] [blame] | 69 | proxy.web(req, res); |
| 70 | } |
| 71 | else{ |
| 72 | next(); |
| 73 | } |
| 74 | } |
| 75 | }, |
| 76 | "port": 3000, |
| 77 | "open": "local" |
| 78 | }; |