Merge "[1707-OS] Updated license text according to the"
[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 = 8181;
7
8 module.exports = function(env) {
9
10     // Set default role
11     if (!env) {
12         env = {
13             role: "designer"
14         };
15     }
16     console.log("Starting dev server with role: " + env.role);
17
18     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];
28
29             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                     next();
36                 }
37             ];
38
39             // Redirect all '/sdc1/feProxy/rest' to feHost
40             middlewares.push(
41                 proxy(['/sdc1/feProxy/rest'],{
42                     target: 'http://localhost:' + fePort,
43                     changeOrigin: true,
44                                     secure: false
45                 }));
46
47             // Redirect dcae urls to feHost
48             middlewares.push(
49                 proxy(['/dcae','/sdc1/feProxy/dcae-api'],{
50                     target: 'http://localhost:' + fePort,
51                     changeOrigin: true,
52                                     secure: false,
53                     onProxyRes: (proxyRes, req, res) => {
54                         let setCookie = proxyRes.headers['set-cookie'];
55                         if (setCookie) {
56                             setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
57                         }
58                     }
59                 }));
60
61             // Redirect onboarding urls to feHost
62             middlewares.push(
63                 proxy(['/onboarding','/sdc1/feProxy/onboarding-api'],{
64                     target: 'http://localhost:' + fePort,
65                     changeOrigin: true,
66                                     secure: false,
67                     onProxyRes: (proxyRes, req, res) => {
68                         let setCookie = proxyRes.headers['set-cookie'];
69                         if (setCookie) {
70                             setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
71                         }
72                     }
73                 }));
74
75             server.use(middlewares);
76         }
77     };
78
79     return ServerConfig;
80 }