blob: 1993617197cf6363c9e33cf4a1f85a2b53fe64bc [file] [log] [blame]
Michael Landoed64b5e2017-06-09 03:19:04 +03001let path = require('path');
2
3const mockApis = require('./configurations/mock.json').sdcConfig;
4const proxy = require('http-proxy-middleware');
5const devPort = 9000;
ys969316a9fce2020-01-19 13:50:02 +02006const fePort = 8287;
7const loclahost = "localhost"; // "localhost"
8const portalCookieValue = "randomValue"; //for dev solely, in production - the webseal would add the cookie byitself.
Michael Landoed64b5e2017-06-09 03:19:04 +03009
10module.exports = function(env) {
11
Michael Landoa5445102018-03-04 14:53:33 +020012 // Set default role
13 if (!env) {
14 env = {
15 role: "designer"
16 };
17 }
18 console.log("Starting dev server with role: " + env.role);
Michael Landoed64b5e2017-06-09 03:19:04 +030019
Michael Landoa5445102018-03-04 14:53:33 +020020 const ServerConfig = {
21 port: devPort,
22 historyApiFallback: true,
23 inline: true,
24 stats: {
25 colors: true,
26 exclude: ['node_modules']
27 },
28 setup: server => {
ys969316a9fce2020-01-19 13:50:02 +020029 let userType = mockApis.userTypes[env.role];
Michael Landoed64b5e2017-06-09 03:19:04 +030030
ys969316a9fce2020-01-19 13:50:02 +020031 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 Landoa5445102018-03-04 14:53:33 +020041
ys969316a9fce2020-01-19 13:50:02 +020042 // 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 Landoa5445102018-03-04 14:53:33 +020049
ys969316a9fce2020-01-19 13:50:02 +020050 // 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 Amitfad1d732018-03-13 19:59:46 +020057
ys969316a9fce2020-01-19 13:50:02 +020058 // 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 Landoa5445102018-03-04 14:53:33 +020071
ys969316a9fce2020-01-19 13:50:02 +020072 // 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 Landoa5445102018-03-04 14:53:33 +020085
ys969316a9fce2020-01-19 13:50:02 +020086 server.use(middlewares);
87}
88};
Michael Landoa5445102018-03-04 14:53:33 +020089
90 return ServerConfig;
Idan Amitfad1d732018-03-13 19:59:46 +020091}