blob: 3418583aab2b7978a89115f147a7eba3aa2c3eea [file] [log] [blame]
Matteo Scandolo5d568612016-01-26 11:02:16 -08001
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
16var httpProxy = require('http-proxy');
17var environment = process.env.NODE_ENV;
18
19if (environment){
Matteo Scandolo0a17d5c2016-01-26 11:34:15 -080020 var conf = require(`./env/${environment}.js`);
Matteo Scandolo5d568612016-01-26 11:02:16 -080021}
22else{
Matteo Scandolo0a17d5c2016-01-26 11:34:15 -080023 var conf = require('./env/default.js')
Matteo Scandolo5d568612016-01-26 11:02:16 -080024}
25
26var proxy = httpProxy.createProxyServer({
Matteo Scandolo0a17d5c2016-01-26 11:34:15 -080027 target: conf.host || 'http://0.0.0.0:9999'
Matteo Scandolo5d568612016-01-26 11:02:16 -080028});
29
30proxy.on('error', function(error, req, res) {
Matteo Scandolo0a17d5c2016-01-26 11:34:15 -080031 res.writeHead(500, {
32 'Content-Type': 'text/plain'
33 });
34 console.error('[Proxy]', error);
Matteo Scandolo5d568612016-01-26 11:02:16 -080035});
36
37module.exports = {
Matteo Scandolo0a17d5c2016-01-26 11:34:15 -080038 "files": [
39 './src/**/*'
40 ],
41 "server": {
42 baseDir: './src',
43 middleware: function(req, res, next){
44 if(
45 req.url.indexOf('/xos/') !== -1 ||
46 req.url.indexOf('/xoslib/') !== -1 ||
47 req.url.indexOf('/hpcapi/') !== -1 ||
48 req.url.indexOf('/rs/') !== -1
49 ){
50 if(conf.xoscsrftoken && conf.xossessionid){
51 req.headers.cookie = `xoscsrftoken=${conf.xoscsrftoken}; xossessionid=${conf.xossessionid}`;
52 req.headers['x-csrftoken'] = conf.xoscsrftoken;
Matteo Scandolo5d568612016-01-26 11:02:16 -080053 }
Matteo Scandolo0a17d5c2016-01-26 11:34:15 -080054 proxy.web(req, res);
55 }
56 else{
57 next();
58 }
59 }
60 },
61 "port": 3000,
62 "open": "local"
Matteo Scandolo5d568612016-01-26 11:02:16 -080063};