blob: b3675773bf3b1517c1bf9bf364f5cfbb7f0f4d26 [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;
andre.schmidc5d39ed2020-02-17 10:11:54 +00004const fePort = 8181;
5const feHost = "localhost";
6const portalCookieValue = "randomValue"; //for dev solely, in production - the webseal would add the cookie by itself.
Michael Landoed64b5e2017-06-09 03:19:04 +03007
andre.schmidc5d39ed2020-02-17 10:11:54 +00008module.exports = function (env) {
Michael Landoed64b5e2017-06-09 03:19:04 +03009
andre.schmidc5d39ed2020-02-17 10:11:54 +000010 // Set default user role
11 if (!env) {
12 env = {
13 role: "designer"
14 };
15 }
16 console.log("Starting dev server with role: " + env.role);
Michael Landoed64b5e2017-06-09 03:19:04 +030017
andre.schmidc5d39ed2020-02-17 10:11:54 +000018 const serverConfig = {
19 port: devPort,
20 historyApiFallback: true,
21 inline: true,
22 stats: {
23 colors: true,
24 exclude: ['node_modules']
25 },
26 setup: server => {
27 let userType = mockApis.userTypes[env.role];
Michael Landoed64b5e2017-06-09 03:19:04 +030028
andre.schmidc5d39ed2020-02-17 10:11:54 +000029 let middlewares = [
30 (req, res, next) => {
31 res.cookie(mockApis.cookie.userIdSuffix, req.headers[mockApis.cookie.userIdSuffix] || userType.userId);
32 res.cookie(mockApis.cookie.userEmail, req.headers[mockApis.cookie.userEmail] || userType.email);
33 res.cookie(mockApis.cookie.userFirstName, req.headers[mockApis.cookie.userFirstName] || userType.firstName);
34 res.cookie(mockApis.cookie.userLastName, req.headers[mockApis.cookie.userLastName] || userType.lastName);
35 res.cookie(mockApis.cookie.portalCookie, portalCookieValue);
36 next();
37 }
38 ];
Michael Landoa5445102018-03-04 14:53:33 +020039
andre.schmidc5d39ed2020-02-17 10:11:54 +000040 // Redirect all '/sdc1/feProxy/rest' to feHost
41 middlewares.push(
42 proxy(['/sdc1/feProxy/rest', '/sdc1/feProxy/uicache'], {
43 target: 'http://' + feHost + ':' + fePort,
44 changeOrigin: true,
45 secure: false
46 }));
Michael Landoa5445102018-03-04 14:53:33 +020047
andre.schmidc5d39ed2020-02-17 10:11:54 +000048 // Redirect all '/sdc1/rest' to feHost
49 middlewares.push(
50 proxy(['/sdc1/rest'], {
51 target: 'http://' + feHost + ':' + fePort,
52 changeOrigin: true,
53 secure: false
54 }));
Idan Amitfad1d732018-03-13 19:59:46 +020055
andre.schmidc5d39ed2020-02-17 10:11:54 +000056 // Redirect dcae urls to feHost
57 middlewares.push(
58 proxy(['/dcae', '/sdc1/feProxy/dcae-api'], {
59 target: 'http://' + feHost + ':' + fePort,
60 changeOrigin: true,
61 secure: false,
62 onProxyRes: (proxyRes, req, res) => {
63 let setCookie = proxyRes.headers['set-cookie'];
64 if (setCookie) {
65 setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
66 }
67 }
68 }));
Michael Landoa5445102018-03-04 14:53:33 +020069
andre.schmidc5d39ed2020-02-17 10:11:54 +000070 // Redirect onboarding urls to feHost
71 middlewares.push(
72 proxy(['/onboarding', '/sdc1/feProxy/onboarding-api'], {
73 target: 'http://' + feHost + ':' + fePort,
74 changeOrigin: true,
75 secure: false,
76 onProxyRes: (proxyRes, req, res) => {
77 let setCookie = proxyRes.headers['set-cookie'];
78 if (setCookie) {
79 setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
80 }
81 }
82 }));
Michael Landoa5445102018-03-04 14:53:33 +020083
andre.schmidc5d39ed2020-02-17 10:11:54 +000084 server.use(middlewares);
85 }
86 };
87
88 return serverConfig;
ys969316a9fce2020-01-19 13:50:02 +020089};