blob: a3db60f63680e8f408108c992e0bebd993a38d88 [file] [log] [blame]
Michael Landoed64b5e2017-06-09 03:19:04 +03001const mockApis = require('./configurations/mock.json').sdcConfig;
2const proxy = require('http-proxy-middleware');
3const devPort = 9000;
ilanap94e77782020-04-01 14:25:35 +03004
andre.schmidc5d39ed2020-02-17 10:11:54 +00005const fePort = 8181;
6const feHost = "localhost";
ilanap94e77782020-04-01 14:25:35 +03007const protocol="http";
andre.schmidac26dc02020-04-21 14:01:21 +01008const isDirectToFE = true;
ilanap94e77782020-04-01 14:25:35 +03009
andre.schmidc5d39ed2020-02-17 10:11:54 +000010const portalCookieValue = "randomValue"; //for dev solely, in production - the webseal would add the cookie by itself.
Michael Landoed64b5e2017-06-09 03:19:04 +030011
andre.schmidc5d39ed2020-02-17 10:11:54 +000012module.exports = function (env) {
Michael Landoed64b5e2017-06-09 03:19:04 +030013
andre.schmidc5d39ed2020-02-17 10:11:54 +000014 // 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 Landoed64b5e2017-06-09 03:19:04 +030021
andre.schmidc5d39ed2020-02-17 10:11:54 +000022 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 Landoed64b5e2017-06-09 03:19:04 +030032
andre.schmidc5d39ed2020-02-17 10:11:54 +000033 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 Landoa5445102018-03-04 14:53:33 +020043
andre.schmidc5d39ed2020-02-17 10:11:54 +000044 // Redirect all '/sdc1/feProxy/rest' to feHost
ilanap94e77782020-04-01 14:25:35 +030045 let feProxyOptions = {
46 target: protocol + '://' + feHost + ':' + fePort,
47 changeOrigin: true,
48 secure: false,
49 logLevel: 'debug'
50 }
andre.schmidac26dc02020-04-21 14:01:21 +010051 if (!isDirectToFE) {
52 feProxyOptions.pathRewrite= {
53 '^/sdc1/feProxy/rest' : '/sdc2/rest'
54 }
55 }
andre.schmidc5d39ed2020-02-17 10:11:54 +000056 middlewares.push(
ilanap94e77782020-04-01 14:25:35 +030057 proxy(['/sdc1/feProxy/rest'], feProxyOptions));
Michael Landoa5445102018-03-04 14:53:33 +020058
andre.schmid161b1a22020-04-21 14:13:17 +010059 // 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.schmidc5d39ed2020-02-17 10:11:54 +000067 // Redirect all '/sdc1/rest' to feHost
68 middlewares.push(
ilanap94e77782020-04-01 14:25:35 +030069 proxy(['/sdc1/rest'],{
70 target: protocol + '://' + feHost + ':' + fePort,
andre.schmidc5d39ed2020-02-17 10:11:54 +000071 changeOrigin: true,
72 secure: false
73 }));
Idan Amitfad1d732018-03-13 19:59:46 +020074
andre.schmidc5d39ed2020-02-17 10:11:54 +000075 // Redirect dcae urls to feHost
76 middlewares.push(
ilanap94e77782020-04-01 14:25:35 +030077 proxy(['/dcae','/sdc1/feProxy/dcae-api'], {
78 target: protocol + '://' + feHost + ':' + fePort,
andre.schmidc5d39ed2020-02-17 10:11:54 +000079 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 Landoa5445102018-03-04 14:53:33 +020088
andre.schmidc5d39ed2020-02-17 10:11:54 +000089 // Redirect onboarding urls to feHost
90 middlewares.push(
91 proxy(['/onboarding', '/sdc1/feProxy/onboarding-api'], {
ilanap94e77782020-04-01 14:25:35 +030092 target: protocol + '://' + feHost + ':' + fePort,
andre.schmidc5d39ed2020-02-17 10:11:54 +000093 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 Landoa5445102018-03-04 14:53:33 +0200102
ilanap94e77782020-04-01 14:25:35 +0300103 // Redirect workflow urls to feHost
104 middlewares.push(
andre.schmidac26dc02020-04-21 14:01:21 +0100105 proxy(['/wf', '/sdc1/feProxy/wf'], {
106 target: protocol + '://' + feHost + ':' + fePort,
ilanap94e77782020-04-01 14:25:35 +0300107 changeOrigin: true,
108 logLevel: 'debug',
109 secure: false,
ilanap94e77782020-04-01 14:25:35 +0300110 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.schmidc5d39ed2020-02-17 10:11:54 +0000117 server.use(middlewares);
118 }
119 };
120
121 return serverConfig;
ys969316a9fce2020-01-19 13:50:02 +0200122};