Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 1 | const mockApis = require('./configurations/mock.json').sdcConfig; |
| 2 | const proxy = require('http-proxy-middleware'); |
| 3 | const devPort = 9000; |
ilanap | 94e7778 | 2020-04-01 14:25:35 +0300 | [diff] [blame] | 4 | |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 5 | const fePort = 8181; |
| 6 | const feHost = "localhost"; |
ilanap | 94e7778 | 2020-04-01 14:25:35 +0300 | [diff] [blame] | 7 | const protocol="http"; |
| 8 | const isDirectToFE = false; |
| 9 | |
| 10 | /* |
| 11 | For kubernetes |
| 12 | const fePort = 30207; |
| 13 | const wfPort = 30256; |
| 14 | const feHost = "kubernetes_master"; |
| 15 | const protocol="https"; |
| 16 | const isDirectToFE = true;// whether to proxy to the k8s proxy or to the BE |
| 17 | */ |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 18 | const portalCookieValue = "randomValue"; //for dev solely, in production - the webseal would add the cookie by itself. |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 19 | |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 20 | module.exports = function (env) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 21 | |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 22 | // Set default user role |
| 23 | if (!env) { |
| 24 | env = { |
| 25 | role: "designer" |
| 26 | }; |
| 27 | } |
| 28 | console.log("Starting dev server with role: " + env.role); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 29 | |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 30 | const serverConfig = { |
| 31 | port: devPort, |
| 32 | historyApiFallback: true, |
| 33 | inline: true, |
| 34 | stats: { |
| 35 | colors: true, |
| 36 | exclude: ['node_modules'] |
| 37 | }, |
| 38 | setup: server => { |
| 39 | let userType = mockApis.userTypes[env.role]; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 40 | |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 41 | let middlewares = [ |
| 42 | (req, res, next) => { |
| 43 | res.cookie(mockApis.cookie.userIdSuffix, req.headers[mockApis.cookie.userIdSuffix] || userType.userId); |
| 44 | res.cookie(mockApis.cookie.userEmail, req.headers[mockApis.cookie.userEmail] || userType.email); |
| 45 | res.cookie(mockApis.cookie.userFirstName, req.headers[mockApis.cookie.userFirstName] || userType.firstName); |
| 46 | res.cookie(mockApis.cookie.userLastName, req.headers[mockApis.cookie.userLastName] || userType.lastName); |
| 47 | res.cookie(mockApis.cookie.portalCookie, portalCookieValue); |
| 48 | next(); |
| 49 | } |
| 50 | ]; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 51 | |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 52 | // Redirect all '/sdc1/feProxy/rest' to feHost |
ilanap | 94e7778 | 2020-04-01 14:25:35 +0300 | [diff] [blame] | 53 | let feProxyOptions = { |
| 54 | target: protocol + '://' + feHost + ':' + fePort, |
| 55 | changeOrigin: true, |
| 56 | secure: false, |
| 57 | logLevel: 'debug' |
| 58 | } |
| 59 | if (isDirectToFE) { |
| 60 | feProxyOptions.pathRewrite= { |
| 61 | '^/sdc1/feProxy/rest' : '/sdc1/feProxy/rest' |
| 62 | } |
| 63 | } else { |
| 64 | feProxyOptions.pathRewrite= { |
| 65 | '^/sdc1/feProxy/rest' : '/sdc2/rest' |
| 66 | } |
| 67 | } |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 68 | middlewares.push( |
ilanap | 94e7778 | 2020-04-01 14:25:35 +0300 | [diff] [blame] | 69 | proxy(['/sdc1/feProxy/rest'], feProxyOptions)); |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 70 | |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 71 | // Redirect all '/sdc1/rest' to feHost |
| 72 | middlewares.push( |
ilanap | 94e7778 | 2020-04-01 14:25:35 +0300 | [diff] [blame] | 73 | proxy(['/sdc1/rest'],{ |
| 74 | target: protocol + '://' + feHost + ':' + fePort, |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 75 | changeOrigin: true, |
| 76 | secure: false |
| 77 | })); |
Idan Amit | fad1d73 | 2018-03-13 19:59:46 +0200 | [diff] [blame] | 78 | |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 79 | // Redirect dcae urls to feHost |
| 80 | middlewares.push( |
ilanap | 94e7778 | 2020-04-01 14:25:35 +0300 | [diff] [blame] | 81 | proxy(['/dcae','/sdc1/feProxy/dcae-api'], { |
| 82 | target: protocol + '://' + feHost + ':' + fePort, |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 83 | changeOrigin: true, |
| 84 | secure: false, |
| 85 | onProxyRes: (proxyRes, req, res) => { |
| 86 | let setCookie = proxyRes.headers['set-cookie']; |
| 87 | if (setCookie) { |
| 88 | setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, ''); |
| 89 | } |
| 90 | } |
| 91 | })); |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 92 | |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 93 | // Redirect onboarding urls to feHost |
| 94 | middlewares.push( |
| 95 | proxy(['/onboarding', '/sdc1/feProxy/onboarding-api'], { |
ilanap | 94e7778 | 2020-04-01 14:25:35 +0300 | [diff] [blame] | 96 | target: protocol + '://' + feHost + ':' + fePort, |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 97 | changeOrigin: true, |
| 98 | secure: false, |
| 99 | onProxyRes: (proxyRes, req, res) => { |
| 100 | let setCookie = proxyRes.headers['set-cookie']; |
| 101 | if (setCookie) { |
| 102 | setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, ''); |
| 103 | } |
| 104 | } |
| 105 | })); |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 106 | |
ilanap | 94e7778 | 2020-04-01 14:25:35 +0300 | [diff] [blame] | 107 | // Redirect workflow urls to feHost |
| 108 | middlewares.push( |
| 109 | proxy(['/sdc1/feProxy/wf', '/wf'], { |
| 110 | target: protocol + '://' + feHost + ':' + wfPort, |
| 111 | changeOrigin: true, |
| 112 | logLevel: 'debug', |
| 113 | secure: false, |
| 114 | pathRewrite: { |
| 115 | '^/sdc1/feProxy' : '' |
| 116 | }, |
| 117 | onProxyRes: (proxyRes, req, res) => { |
| 118 | let setCookie = proxyRes.headers['set-cookie']; |
| 119 | if (setCookie) { |
| 120 | setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, ''); |
| 121 | } |
| 122 | } |
| 123 | })); |
andre.schmid | c5d39ed | 2020-02-17 10:11:54 +0000 | [diff] [blame] | 124 | server.use(middlewares); |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | return serverConfig; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 129 | }; |