blob: 608063aa02bccf55c7531e2ac1a1c300cec7416c [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;
Michael Landoa5445102018-03-04 14:53:33 +02007const loclahost = "192.168.33.10"; // "localhost"
Michael Landoed64b5e2017-06-09 03:19:04 +03008
9module.exports = function(env) {
10
Michael Landoa5445102018-03-04 14:53:33 +020011 // Set default role
12 if (!env) {
13 env = {
14 role: "designer"
15 };
16 }
17 console.log("Starting dev server with role: " + env.role);
Michael Landoed64b5e2017-06-09 03:19:04 +030018
Michael Landoa5445102018-03-04 14:53:33 +020019 const ServerConfig = {
20 port: devPort,
21 historyApiFallback: true,
22 inline: true,
23 stats: {
24 colors: true,
25 exclude: ['node_modules']
26 },
27 setup: server => {
28 let userType = mockApis.userTypes[env.role];
Michael Landoed64b5e2017-06-09 03:19:04 +030029
Michael Landoa5445102018-03-04 14:53:33 +020030 let middlewares = [
31 (req, res, next) => {
32 res.cookie(mockApis.cookie.userIdSuffix, req.headers[mockApis.cookie.userIdSuffix] || userType.userId);
33 res.cookie(mockApis.cookie.userEmail, req.headers[mockApis.cookie.userEmail] || userType.email);
34 res.cookie(mockApis.cookie.userFirstName, req.headers[mockApis.cookie.userFirstName] || userType.firstName);
35 res.cookie(mockApis.cookie.userLastName, req.headers[mockApis.cookie.userLastName] || userType.lastName);
36 next();
Idan Amit2c285722017-12-29 09:40:43 +020037}
Michael Landoa5445102018-03-04 14:53:33 +020038];
39
40 // Redirect all '/sdc1/feProxy/rest' to feHost
41 middlewares.push(
42 proxy(['/sdc1/feProxy/rest'],{
43 target: 'http://' + loclahost + ':' + fePort,
44 changeOrigin: true,
45 secure: false
46 }));
47
48 // Redirect dcae urls to feHost
49 middlewares.push(
50 proxy(['/dcae','/sdc1/feProxy/dcae-api'],{
51 target: 'http://' + loclahost + ':' + fePort,
52 changeOrigin: true,
53 secure: false,
54 onProxyRes: (proxyRes, req, res) => {
55 let setCookie = proxyRes.headers['set-cookie'];
56 if (setCookie) {
57 setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
58 }
59}
60}));
61
62 // Redirect onboarding urls to feHost
63 middlewares.push(
64 proxy(['/onboarding','/sdc1/feProxy/onboarding-api'],{
65 target: 'http://' + loclahost + ':' + fePort,
66 changeOrigin: true,
67 secure: false,
68 onProxyRes: (proxyRes, req, res) => {
69 let setCookie = proxyRes.headers['set-cookie'];
70 if (setCookie) {
71 setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
72 }
73}
74}));
75
76 server.use(middlewares);
77}
78};
79
80 return ServerConfig;
81}