blob: 7d88e523c2fe27c22539489bdac2099950e770dc [file] [log] [blame]
Matteo Scandolobf14f882016-06-02 10:01:34 -07001
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){
20 var conf = require(`./env/${environment}.js`);
21}
22else{
23 var conf = require('./env/default.js')
24}
25
26var proxy = httpProxy.createProxyServer({
27 target: conf.host || 'http://0.0.0.0:9999'
28});
29
30proxy.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
39module.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 }
67 console.log(`proxied: ${req.url}`, req.headers['x-csrftoken'], req.headers.cookie);
68 proxy.web(req, res);
69 }
70 else{
71 next();
72 }
73 }
74 },
75 "port": 3000,
76 "open": "local"
77};