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; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 6 | const fePort = 8287; |
| 7 | const loclahost = "localhost"; // "localhost" |
| 8 | const portalCookieValue = "randomValue"; //for dev solely, in production - the webseal would add the cookie byitself. |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 9 | |
| 10 | module.exports = function(env) { |
| 11 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 12 | // Set default role |
| 13 | if (!env) { |
| 14 | env = { |
| 15 | role: "designer" |
| 16 | }; |
| 17 | } |
| 18 | console.log("Starting dev server with role: " + env.role); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 19 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 20 | const ServerConfig = { |
| 21 | port: devPort, |
| 22 | historyApiFallback: true, |
| 23 | inline: true, |
| 24 | stats: { |
| 25 | colors: true, |
| 26 | exclude: ['node_modules'] |
| 27 | }, |
| 28 | setup: server => { |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 29 | let userType = mockApis.userTypes[env.role]; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 30 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 31 | let middlewares = [ |
| 32 | (req, res, next) => { |
| 33 | res.cookie(mockApis.cookie.userIdSuffix, req.headers[mockApis.cookie.userIdSuffix] || userType.userId); |
| 34 | res.cookie(mockApis.cookie.userEmail, req.headers[mockApis.cookie.userEmail] || userType.email); |
| 35 | res.cookie(mockApis.cookie.userFirstName, req.headers[mockApis.cookie.userFirstName] || userType.firstName); |
| 36 | res.cookie(mockApis.cookie.userLastName, req.headers[mockApis.cookie.userLastName] || userType.lastName); |
| 37 | res.cookie(mockApis.cookie.portalCookie, portalCookieValue); |
| 38 | next(); |
| 39 | } |
| 40 | ]; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 41 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 42 | // Redirect all '/sdc1/feProxy/rest' to feHost |
| 43 | middlewares.push( |
| 44 | proxy(['/sdc1/feProxy/rest', '/sdc1/feProxy/uicache'],{ |
| 45 | target: 'http://' + loclahost + ':' + fePort, |
| 46 | changeOrigin: true, |
| 47 | secure: false |
| 48 | })); |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 49 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 50 | // Redirect all '/sdc1/rest' to feHost |
| 51 | middlewares.push( |
| 52 | proxy(['/sdc1/rest'],{ |
| 53 | target: 'http://' + loclahost + ':' + fePort, |
| 54 | changeOrigin: true, |
| 55 | secure: false |
| 56 | })); |
Idan Amit | fad1d73 | 2018-03-13 19:59:46 +0200 | [diff] [blame] | 57 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 58 | // Redirect dcae urls to feHost |
| 59 | middlewares.push( |
| 60 | proxy(['/dcae','/sdc1/feProxy/dcae-api'],{ |
| 61 | target: 'http://' + loclahost + ':' + fePort, |
| 62 | changeOrigin: true, |
| 63 | secure: false, |
| 64 | onProxyRes: (proxyRes, req, res) => { |
| 65 | let setCookie = proxyRes.headers['set-cookie']; |
| 66 | if (setCookie) { |
| 67 | setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, ''); |
| 68 | } |
| 69 | } |
| 70 | })); |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 71 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 72 | // Redirect onboarding urls to feHost |
| 73 | middlewares.push( |
| 74 | proxy(['/onboarding','/sdc1/feProxy/onboarding-api'],{ |
| 75 | target: 'http://' + loclahost + ':' + fePort, |
| 76 | changeOrigin: true, |
| 77 | secure: false, |
| 78 | onProxyRes: (proxyRes, req, res) => { |
| 79 | let setCookie = proxyRes.headers['set-cookie']; |
| 80 | if (setCookie) { |
| 81 | setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, ''); |
| 82 | } |
| 83 | } |
| 84 | })); |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 85 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 86 | server.use(middlewares); |
| 87 | } |
| 88 | }; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 89 | |
| 90 | return ServerConfig; |
Idan Amit | fad1d73 | 2018-03-13 19:59:46 +0200 | [diff] [blame] | 91 | } |