1 const mockApis = require('./configurations/mock.json').sdcConfig;
2 const proxy = require('http-proxy-middleware');
6 const feHost = "localhost";
8 const isDirectToFE = false;
14 const feHost = "kubernetes_master";
15 const protocol="https";
16 const isDirectToFE = true;// whether to proxy to the k8s proxy or to the BE
18 const portalCookieValue = "randomValue"; //for dev solely, in production - the webseal would add the cookie by itself.
20 module.exports = function (env) {
22 // Set default user role
28 console.log("Starting dev server with role: " + env.role);
30 const serverConfig = {
32 historyApiFallback: true,
36 exclude: ['node_modules']
39 let userType = mockApis.userTypes[env.role];
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);
52 // Redirect all '/sdc1/feProxy/rest' to feHost
53 let feProxyOptions = {
54 target: protocol + '://' + feHost + ':' + fePort,
60 feProxyOptions.pathRewrite= {
61 '^/sdc1/feProxy/rest' : '/sdc1/feProxy/rest'
64 feProxyOptions.pathRewrite= {
65 '^/sdc1/feProxy/rest' : '/sdc2/rest'
69 proxy(['/sdc1/feProxy/rest'], feProxyOptions));
71 // Redirect all '/sdc1/rest' to feHost
73 proxy(['/sdc1/rest'],{
74 target: protocol + '://' + feHost + ':' + fePort,
79 // Redirect dcae urls to feHost
81 proxy(['/dcae','/sdc1/feProxy/dcae-api'], {
82 target: protocol + '://' + feHost + ':' + fePort,
85 onProxyRes: (proxyRes, req, res) => {
86 let setCookie = proxyRes.headers['set-cookie'];
88 setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
93 // Redirect onboarding urls to feHost
95 proxy(['/onboarding', '/sdc1/feProxy/onboarding-api'], {
96 target: protocol + '://' + feHost + ':' + fePort,
99 onProxyRes: (proxyRes, req, res) => {
100 let setCookie = proxyRes.headers['set-cookie'];
102 setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
107 // Redirect workflow urls to feHost
109 proxy(['/sdc1/feProxy/wf', '/wf'], {
110 target: protocol + '://' + feHost + ':' + wfPort,
115 '^/sdc1/feProxy' : ''
117 onProxyRes: (proxyRes, req, res) => {
118 let setCookie = proxyRes.headers['set-cookie'];
120 setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
124 server.use(middlewares);