blob: 0d43fa1d864d0489e74326b1066984bbe8df4477 [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";
8const isDirectToFE = false;
9
10/*
11For kubernetes
12const fePort = 30207;
13const wfPort = 30256;
14const feHost = "kubernetes_master";
15const protocol="https";
16const isDirectToFE = true;// whether to proxy to the k8s proxy or to the BE
17*/
andre.schmidc5d39ed2020-02-17 10:11:54 +000018const portalCookieValue = "randomValue"; //for dev solely, in production - the webseal would add the cookie by itself.
Michael Landoed64b5e2017-06-09 03:19:04 +030019
andre.schmidc5d39ed2020-02-17 10:11:54 +000020module.exports = function (env) {
Michael Landoed64b5e2017-06-09 03:19:04 +030021
andre.schmidc5d39ed2020-02-17 10:11:54 +000022 // 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 Landoed64b5e2017-06-09 03:19:04 +030029
andre.schmidc5d39ed2020-02-17 10:11:54 +000030 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 Landoed64b5e2017-06-09 03:19:04 +030040
andre.schmidc5d39ed2020-02-17 10:11:54 +000041 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 Landoa5445102018-03-04 14:53:33 +020051
andre.schmidc5d39ed2020-02-17 10:11:54 +000052 // Redirect all '/sdc1/feProxy/rest' to feHost
ilanap94e77782020-04-01 14:25:35 +030053 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.schmidc5d39ed2020-02-17 10:11:54 +000068 middlewares.push(
ilanap94e77782020-04-01 14:25:35 +030069 proxy(['/sdc1/feProxy/rest'], feProxyOptions));
Michael Landoa5445102018-03-04 14:53:33 +020070
andre.schmidc5d39ed2020-02-17 10:11:54 +000071 // Redirect all '/sdc1/rest' to feHost
72 middlewares.push(
ilanap94e77782020-04-01 14:25:35 +030073 proxy(['/sdc1/rest'],{
74 target: protocol + '://' + feHost + ':' + fePort,
andre.schmidc5d39ed2020-02-17 10:11:54 +000075 changeOrigin: true,
76 secure: false
77 }));
Idan Amitfad1d732018-03-13 19:59:46 +020078
andre.schmidc5d39ed2020-02-17 10:11:54 +000079 // Redirect dcae urls to feHost
80 middlewares.push(
ilanap94e77782020-04-01 14:25:35 +030081 proxy(['/dcae','/sdc1/feProxy/dcae-api'], {
82 target: protocol + '://' + feHost + ':' + fePort,
andre.schmidc5d39ed2020-02-17 10:11:54 +000083 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 Landoa5445102018-03-04 14:53:33 +020092
andre.schmidc5d39ed2020-02-17 10:11:54 +000093 // Redirect onboarding urls to feHost
94 middlewares.push(
95 proxy(['/onboarding', '/sdc1/feProxy/onboarding-api'], {
ilanap94e77782020-04-01 14:25:35 +030096 target: protocol + '://' + feHost + ':' + fePort,
andre.schmidc5d39ed2020-02-17 10:11:54 +000097 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 Landoa5445102018-03-04 14:53:33 +0200106
ilanap94e77782020-04-01 14:25:35 +0300107 // 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.schmidc5d39ed2020-02-17 10:11:54 +0000124 server.use(middlewares);
125 }
126 };
127
128 return serverConfig;
ys969316a9fce2020-01-19 13:50:02 +0200129};