Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 1 | let path = require('path'); |
| 2 | |
| 3 | const mockApis = require('./configurations/mock.json').sdcConfig; |
| 4 | const proxy = require('http-proxy-middleware'); |
| 5 | const devPort = 9000; |
| 6 | const fePort = 8181; |
Arielk | eaaf801 | 2018-07-31 12:59:36 +0300 | [diff] [blame^] | 7 | const localhost = "localhost"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 8 | |
| 9 | module.exports = function(env) { |
| 10 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 11 | // Set default role |
| 12 | if (!env) { |
| 13 | env = { |
| 14 | role: "designer" |
| 15 | }; |
| 16 | } |
| 17 | console.log("Starting dev server with role: " + env.role); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 18 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 19 | const ServerConfig = { |
| 20 | port: devPort, |
| 21 | historyApiFallback: true, |
| 22 | inline: true, |
| 23 | stats: { |
| 24 | colors: true, |
| 25 | exclude: ['node_modules'] |
| 26 | }, |
| 27 | setup: server => { |
Arielk | eaaf801 | 2018-07-31 12:59:36 +0300 | [diff] [blame^] | 28 | let userType = mockApis.userTypes[env.role]; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 29 | |
Arielk | eaaf801 | 2018-07-31 12:59:36 +0300 | [diff] [blame^] | 30 | let middlewares = [ |
| 31 | (req, res, next) => { |
| 32 | res.cookie(mockApis.cookie.userIdSuffix, req.headers[mockApis.cookie.userIdSuffix] || userType.userId); |
| 33 | res.cookie(mockApis.cookie.userEmail, req.headers[mockApis.cookie.userEmail] || userType.email); |
| 34 | res.cookie(mockApis.cookie.userFirstName, req.headers[mockApis.cookie.userFirstName] || userType.firstName); |
| 35 | res.cookie(mockApis.cookie.userLastName, req.headers[mockApis.cookie.userLastName] || userType.lastName); |
| 36 | next(); |
| 37 | } |
| 38 | ]; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 39 | |
Arielk | eaaf801 | 2018-07-31 12:59:36 +0300 | [diff] [blame^] | 40 | // Redirect all '/sdc1/feProxy/rest' to feHost |
| 41 | middlewares.push( |
| 42 | proxy(['/sdc1/feProxy/rest'], { |
| 43 | target: 'http://' + localhost + ':' + fePort, |
| 44 | changeOrigin: true, |
| 45 | secure: false |
| 46 | })); |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 47 | |
Arielk | eaaf801 | 2018-07-31 12:59:36 +0300 | [diff] [blame^] | 48 | // Redirect all '/sdc1/rest' to feHost |
| 49 | middlewares.push( |
| 50 | proxy(['/sdc1/rest'],{ |
| 51 | target: 'http://' + localhost + ':' + fePort, |
| 52 | changeOrigin: true, |
| 53 | secure: false |
| 54 | })); |
Idan Amit | fad1d73 | 2018-03-13 19:59:46 +0200 | [diff] [blame] | 55 | |
Arielk | eaaf801 | 2018-07-31 12:59:36 +0300 | [diff] [blame^] | 56 | // Redirect dcae urls to feHost |
| 57 | middlewares.push( |
| 58 | proxy(['/dcae','/sdc1/feProxy/dcae-api'], { |
| 59 | target: 'http://' + localhost + ':' + fePort, |
| 60 | changeOrigin: true, |
| 61 | secure: false, |
| 62 | onProxyRes: (proxyRes, req, res) => { |
| 63 | let setCookie = proxyRes.headers['set-cookie']; |
| 64 | if (setCookie) { |
| 65 | setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, ''); |
| 66 | } |
| 67 | } |
| 68 | })); |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 69 | |
Arielk | eaaf801 | 2018-07-31 12:59:36 +0300 | [diff] [blame^] | 70 | // Redirect onboarding urls to feHost |
| 71 | middlewares.push( |
| 72 | proxy(['/onboarding', '/sdc1/feProxy/onboarding-api'], { |
| 73 | target: 'http://' + localhost + ':' + fePort, |
| 74 | changeOrigin: true, |
| 75 | secure: false, |
| 76 | onProxyRes: (proxyRes, req, res) => { |
| 77 | let setCookie = proxyRes.headers['set-cookie']; |
| 78 | if (setCookie) { |
| 79 | setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, ''); |
| 80 | } |
| 81 | } |
| 82 | })); |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 83 | |
Arielk | eaaf801 | 2018-07-31 12:59:36 +0300 | [diff] [blame^] | 84 | // Redirect workflow urls to feHost |
| 85 | middlewares.push( |
| 86 | proxy(['/sdc1/feProxy/wf', '/wf'], { |
| 87 | target: 'http://' + localhost + ':' + fePort, |
| 88 | changeOrigin: true, |
| 89 | secure: false, |
| 90 | onProxyRes: (proxyRes, req, res) => { |
| 91 | let setCookie = proxyRes.headers['set-cookie']; |
| 92 | if (setCookie) { |
| 93 | setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, ''); |
| 94 | } |
| 95 | } |
| 96 | })); |
| 97 | |
| 98 | server.use(middlewares); |
| 99 | } |
| 100 | }; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 101 | |
| 102 | return ServerConfig; |
Idan Amit | fad1d73 | 2018-03-13 19:59:46 +0200 | [diff] [blame] | 103 | } |