blob: c4fc07b8b65082069a3e8f7b174cc16c869ee070 [file] [log] [blame]
Matteo Scandolo4eb4ccb2016-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 Scandolo9fb53f72016-01-26 11:34:15 -080020 var conf = require(`./env/${environment}.js`);
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -080021}
22else{
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080023 var conf = require('./env/default.js')
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -080024}
25
26var proxy = httpProxy.createProxyServer({
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080027 target: conf.host || 'http://0.0.0.0:9999'
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -080028});
29
30proxy.on('error', function(error, req, res) {
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080031 res.writeHead(500, {
32 'Content-Type': 'text/plain'
33 });
34 console.error('[Proxy]', error);
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -080035});
36
37module.exports = {
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080038 "files": [
Matteo Scandoloa6c02f42016-01-28 15:34:19 -080039 './src/**/*.css',
40 './src/**/*.js',
41 './src/**/*.json'
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080042 ],
43 "server": {
44 baseDir: './src',
Matteo Scandolo3eaeb3e2016-01-28 13:26:50 -080045 //directory: true,
Matteo Scandoloc6036502016-01-26 15:17:10 -080046 routes: {
47 '/rs/dashboard': './mocks/dashboard.json',
48 '/rs/bundle': './mocks/bundle.json',
49 '/rs/users': './mocks/users.json'
50 },
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080051 middleware: function(req, res, next){
52 if(
53 req.url.indexOf('/xos/') !== -1 ||
54 req.url.indexOf('/xoslib/') !== -1 ||
Matteo Scandoloc6036502016-01-26 15:17:10 -080055 req.url.indexOf('/hpcapi/') !== -1
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080056 ){
Matteo Scandolo61f05f52016-01-28 09:41:01 -080057 if(req.headers['X-CSRFToken']){
58 req.headers['x-csrftoken'] = req.headers['x-csrftoken'];
Matteo Scandolob0e65a62016-01-28 11:05:15 -080059 req.headers.cookie = `xoscsrftoken=${req.headers['x-csrftoken']}; xossessionid=${req.headers['sessionid']}`;
Matteo Scandolo61f05f52016-01-28 09:41:01 -080060 }
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080061 proxy.web(req, res);
62 }
63 else{
64 next();
65 }
66 }
67 },
68 "port": 3000,
69 "open": "local"
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -080070};