blob: 507b8d33d4d95096791e3a05de3d426b26312790 [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',
Matteo Scandolo2b545462016-01-26 15:17:10 -080043 routes: {
44 '/rs/dashboard': './mocks/dashboard.json',
45 '/rs/bundle': './mocks/bundle.json',
46 '/rs/users': './mocks/users.json'
47 },
Matteo Scandolo0a17d5c2016-01-26 11:34:15 -080048 middleware: function(req, res, next){
49 if(
50 req.url.indexOf('/xos/') !== -1 ||
51 req.url.indexOf('/xoslib/') !== -1 ||
Matteo Scandolo2b545462016-01-26 15:17:10 -080052 req.url.indexOf('/hpcapi/') !== -1
Matteo Scandolo0a17d5c2016-01-26 11:34:15 -080053 ){
54 if(conf.xoscsrftoken && conf.xossessionid){
55 req.headers.cookie = `xoscsrftoken=${conf.xoscsrftoken}; xossessionid=${conf.xossessionid}`;
56 req.headers['x-csrftoken'] = conf.xoscsrftoken;
Matteo Scandolo5d568612016-01-26 11:02:16 -080057 }
Matteo Scandolo0a17d5c2016-01-26 11:34:15 -080058 proxy.web(req, res);
59 }
60 else{
61 next();
62 }
63 }
64 },
65 "port": 3000,
66 "open": "local"
Matteo Scandolo5d568612016-01-26 11:02:16 -080067};