blob: e703aff6b32650cf1cf9b794af09627c6f7d98d7 [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
Matteo Scandolo3b82a592016-06-21 12:10:35 +020030var onos_proxy = httpProxy.createProxyServer({
31 target: conf.onos_host || 'http://10.50.1.15:8181'
32});
33
Matteo Scandolobf14f882016-06-02 10:01:34 -070034proxy.on('error', function(error, req, res) {
Matteo Scandolobf14f882016-06-02 10:01:34 -070035 console.error('[Proxy]', error);
Matteo Scandolo3b82a592016-06-21 12:10:35 +020036});
37
38onos_proxy.on('error', function(error, req, res) {
39 console.error('[ONOS Proxy]', error);
Matteo Scandolobf14f882016-06-02 10:01:34 -070040});
41
42module.exports = {
43 "files": [
44 './src/**/*.css',
45 './src/**/*.js',
46 './src/**/*.json',
47 './src/**/*.html',
48 './src/**/*.jpg',
49 './src/**/*.png',
50 './src/**/*.gif'
51 ],
52 "server": {
53 baseDir: './src',
54 //directory: true,
55 routes: {
56 '/rs/dashboard': './mocks/dashboard.json',
57 '/rs/bundle': './mocks/bundle.json',
58 '/rs/users': './mocks/users.json'
59 },
60 middleware: function(req, res, next){
61 if(
Matteo Scandolo8cb844e2016-06-02 11:39:02 -070062 req.url.indexOf('/api/') !== -1 ||
Matteo Scandolobf14f882016-06-02 10:01:34 -070063 req.url.indexOf('/xos/') !== -1 ||
64 req.url.indexOf('/xoslib/') !== -1 ||
65 req.url.indexOf('/hpcapi/') !== -1
66 ){
67 if(req.headers['X-CSRFToken']){
68 req.headers['x-csrftoken'] = req.headers['x-csrftoken'];
69 req.headers.cookie = `xoscsrftoken=${req.headers['x-csrftoken']}; xossessionid=${req.headers['sessionid']}`;
70 }
Matteo Scandolobf14f882016-06-02 10:01:34 -070071 proxy.web(req, res);
72 }
Matteo Scandolo3b82a592016-06-21 12:10:35 +020073 else if(req.url.indexOf('/onos/') !== -1){
74 onos_proxy.web(req, res);
75 }
Matteo Scandolobf14f882016-06-02 10:01:34 -070076 else{
77 next();
78 }
79 }
80 },
81 "port": 3000,
82 "open": "local"
83};