blob: e7820dcfa7997114cf74228203f0e443ad1f15b8 [file] [log] [blame]
Matteo Scandolo74802522016-02-25 09:19:41 -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){
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 res.writeHead(500, {
32 'Content-Type': 'text/plain'
33 });
34 console.error('[Proxy]', error);
35});
36
37module.exports = {
38 "files": [
39 './src/**/*.css',
40 './src/**/*.js',
41 './src/**/*.json',
42 './src/**/*.html',
43 './src/**/*.jpg',
44 './src/**/*.png',
45 './src/**/*.gif'
46 ],
47 "server": {
48 baseDir: './src',
49 //directory: true,
50 routes: {
51 '/rs/dashboard': './mocks/dashboard.json',
52 '/rs/bundle': './mocks/bundle.json',
53 '/rs/users': './mocks/users.json'
54 },
55 middleware: function(req, res, next){
56 if(
57 req.url.indexOf('/xos/') !== -1 ||
58 req.url.indexOf('/xoslib/') !== -1 ||
59 req.url.indexOf('/hpcapi/') !== -1
60 ){
61 if(req.headers['X-CSRFToken']){
62 req.headers['x-csrftoken'] = req.headers['x-csrftoken'];
63 req.headers.cookie = `xoscsrftoken=${req.headers['x-csrftoken']}; xossessionid=${req.headers['sessionid']}`;
64 }
65 proxy.web(req, res);
66 }
67 else{
68 next();
69 }
70 }
71 },
72 "port": 3000,
73 "open": "local"
74};