blob: e53d79f533790cdeeb1986079ec5f896ec2a9e0d [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;
6const fePort = 8181;
7
8module.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'],{
Idan Amitb676b6d2018-02-01 14:01:11 +020042 target: 'http://localhost:' + fePort,
Michael Landoed64b5e2017-06-09 03:19:04 +030043 changeOrigin: true,
44 secure: false
45 }));
46
Idan Amit2c285722017-12-29 09:40:43 +020047 middlewares.push(
48 proxy(['/sdc1/rest'],{
Idan Amitb676b6d2018-02-01 14:01:11 +020049 target: 'http://localhost:' + fePort,
Idan Amit2c285722017-12-29 09:40:43 +020050 changeOrigin: true,
51 secure: false
52 }));
53
Michael Landoed64b5e2017-06-09 03:19:04 +030054 // Redirect dcae urls to feHost
55 middlewares.push(
56 proxy(['/dcae','/sdc1/feProxy/dcae-api'],{
Idan Amitb676b6d2018-02-01 14:01:11 +020057 target: 'http://localhost:' + fePort,
Michael Landoed64b5e2017-06-09 03:19:04 +030058 changeOrigin: true,
59 secure: false,
60 onProxyRes: (proxyRes, req, res) => {
61 let setCookie = proxyRes.headers['set-cookie'];
62 if (setCookie) {
63 setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
64 }
65 }
66 }));
67
68 // Redirect onboarding urls to feHost
69 middlewares.push(
70 proxy(['/onboarding','/sdc1/feProxy/onboarding-api'],{
Idan Amitb676b6d2018-02-01 14:01:11 +020071 target: 'http://localhost:' + fePort,
Michael Landoed64b5e2017-06-09 03:19:04 +030072 changeOrigin: true,
73 secure: false,
74 onProxyRes: (proxyRes, req, res) => {
75 let setCookie = proxyRes.headers['set-cookie'];
76 if (setCookie) {
77 setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
78 }
79 }
80 }));
81
82 server.use(middlewares);
83 }
84 };
85
86 return ServerConfig;
Idan Amit2c285722017-12-29 09:40:43 +020087}