blob: dcf8ce3bc1c9c3bf6080036b0a1dc0acffcb710d [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(
Matteo Scandolo8cb844e2016-06-02 11:39:02 -070059 req.url.indexOf('/api/') !== -1 ||
Matteo Scandolobf14f882016-06-02 10:01:34 -070060 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 Scandolo8cb844e2016-06-02 11:39:02 -070068 // console.log(`proxied: ${req.url}`, req.headers['x-csrftoken'], req.headers.cookie);
Matteo Scandolobf14f882016-06-02 10:01:34 -070069 proxy.web(req, res);
70 }
71 else{
72 next();
73 }
74 }
75 },
76 "port": 3000,
77 "open": "local"
78};