Catalog alignment
[sdc.git] / catalog-ui / webpack.server.js
1 let path = require('path');
2
3 const mockApis = require('./configurations/mock.json').sdcConfig;
4 const proxy = require('http-proxy-middleware');
5 const devPort = 9000;
6 const fePort = 8287;
7 const loclahost = "localhost"; // "localhost"
8 const portalCookieValue = "randomValue"; //for dev solely, in production - the webseal would add the cookie byitself.
9
10 module.exports = function(env) {
11
12         // Set default role
13         if (!env) {
14                 env = {
15                         role: "designer"
16                 };
17         }
18         console.log("Starting dev server with role: " + env.role);
19
20         const ServerConfig = {
21                 port: devPort,
22                 historyApiFallback: true,
23                 inline: true,
24                 stats: {
25                         colors: true,
26                         exclude: ['node_modules']
27                 },
28                 setup: server => {
29                 let userType = mockApis.userTypes[env.role];
30
31         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 ];
41
42         // 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                 }));
49
50         // 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                 }));
57
58         // 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 }));
71
72         // 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 }));
85
86         server.use(middlewares);
87 }
88 };
89
90         return ServerConfig;
91 }