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