aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-ui
diff options
context:
space:
mode:
authorilanap <ilanap@amdocs.com>2021-01-17 17:09:35 +0200
committerChristophe Closset <christophe.closset@intl.att.com>2021-01-22 12:32:32 +0000
commit1d8517d50cef8b6e115748541a927227fe06500f (patch)
treee0fe8b79e889c43dcf415ecff28c0303d60128b2 /openecomp-ui
parent7c2593303b78cf8df66134d60af7a0efc54e4f13 (diff)
Fixes for proxy server for onboarding UI
Issue-ID: SDC-3436 Signed-off-by: ilanap <ilanap@amdocs.com> Change-Id: Ie7b83b1a6ad0decdea849f7848f7ffd5af05ce23
Diffstat (limited to 'openecomp-ui')
-rw-r--r--openecomp-ui/devConfig.defaults.json89
-rw-r--r--openecomp-ui/proxy-server.js97
2 files changed, 133 insertions, 53 deletions
diff --git a/openecomp-ui/devConfig.defaults.json b/openecomp-ui/devConfig.defaults.json
index bd86213587..7f89909059 100644
--- a/openecomp-ui/devConfig.defaults.json
+++ b/openecomp-ui/devConfig.defaults.json
@@ -3,24 +3,81 @@
"proxyCatalogTarget": null,
"proxyWebsocketTarget": null,
"proxyTarget": null,
- "proxyConfig": {
- "cookies": null,
- "cookiesReplaceRules": [],
- "urlReplaceRules": [],
- "jsReplaceRules": [],
- "appContextPath": null,
- "login": null,
- "redirectionPath": null,
- "onboardingProxy": {
- "rewrite": null,
- "proxy": []
+ "cookie": {
+ "junctionName": "IV_JCT",
+ "prefix": "AMWEBJCT!",
+ "userIdSuffix": "USER_ID",
+ "userFirstName": "HTTP_CSP_FIRSTNAME",
+ "userLastName": "HTTP_CSP_LASTNAME",
+ "userEmail": "HTTP_CSP_EMAIL",
+ "xEcompRequestId": " X-ECOMP-RequestID",
+ "portalCookie": "EPService"
+ },
+ "env": {
+ "role": "designer"
+ },
+ "userTypes": {
+ "admin": {
+ "userId": "jh0003",
+ "email": "mail@gmail.com",
+ "firstName": "Jimmy",
+ "lastName": "Hendrix",
+ "xEcompRequestId": "ccccc"
},
- "catalogProxy": {
- "rewrite": null,
- "proxy": []
+ "designer": {
+ "userId": "cs0008",
+ "email": "designer@sdc.com",
+ "firstName": "Carlos",
+ "lastName": "Santana",
+ "xEcompRequestId": "ccccc"
+ }
+ },
+ "proxyConfig" : {
+ "urlReplaceRules" : [
+ {
+ "url" : "/proxy-designer1",
+ "replace" : "/proxy-designer1",
+ "with" : ""
+ },
+ {
+ "url" : "/onboarding/resources",
+ "replace" : "/onboarding",
+ "with" : ""
+ }
+ ],
+ "jsReplaceRules" : [
+ {
+ "replace" : "/onboarding/punch-outs_en.js",
+ "with" : "/onboarding/punch-outs.js"
+ }
+ ],
+ "appContextPath" : "/onboarding",
+ "redirectionPath" : "sdc1#/onboardVendor",
+ "onboardingProxy" : {
+ "rewrite" : {
+ "/sdc1/feProxy/onboarding-api": "/onboarding-api"
+ },
+ "proxy" : [
+ "/api",
+ "/onboarding-api",
+ "/sdc1/feProxy/onboarding-api"
+ ]
+ },
+ "catalogProxy" : {
+ "rewrite" : {
+ "/sdc1/feProxy/onboarding-api": "/sdc1/feProxy/onboarding-api",
+ "/onboarding-api": "/sdc1/feProxy/onboarding-api"
+ },
+ "proxy" : [
+ "/sdc1",
+ "/onboarding-api",
+ "/scripts",
+ "/styles"
+ ]
},
- "websocketProxy": {
- "proxy": []
+ "websocketProxy" : {
+ "proxy" : ["/notification-api"],
+ "enabled" : false
}
}
}
diff --git a/openecomp-ui/proxy-server.js b/openecomp-ui/proxy-server.js
index 99685424e2..6db8e61ac1 100644
--- a/openecomp-ui/proxy-server.js
+++ b/openecomp-ui/proxy-server.js
@@ -6,36 +6,50 @@ const devConfig = require('./tools/getDevConfig');
let devPort = process.env.PORT || devConfig.port;
module.exports = function(server) {
- let cookieRules = devConfig.proxyConfig.cookieReplaceRules;
- let cookies = devConfig.proxyConfig.cookies;
+ console.log('');
console.log('---------------------');
+ console.log('---------------------');
+ console.log('---------------------');
+ console.log(
+ 'Local URL: http://localhost:' + devPort + '/sdc1/#!/onboardVendor'
+ );
+ console.log('---------------------');
+ console.log('---------------------');
+ console.log('---------------------');
+ console.log('Starting dev server with role: ' + devConfig.env.role);
+ let userType = devConfig.userTypes[devConfig.env.role];
let proxyConfigDefaults = {
changeOrigin: true,
secure: false,
+ logLevel: 'debug',
onProxyRes: (proxyRes, req, res) => {
- let setCookie = proxyRes.headers['set-cookie'];
- if (setCookie) {
- cookieRules.forEach(function(rule) {
- setCookie[0] = setCookie[0].replace(
- rule.replace,
- rule.with
- );
- });
- }
+ res.cookie(
+ devConfig.cookie.userIdSuffix,
+ req.headers[devConfig.cookie.userIdSuffix] || userType.userId
+ );
+ res.cookie(
+ devConfig.cookie.userEmail,
+ req.headers[devConfig.cookie.userEmail] || userType.email
+ );
+ res.cookie(
+ devConfig.cookie.userFirstName,
+ req.headers[devConfig.cookie.userFirstName] ||
+ userType.firstName
+ );
+ res.cookie(
+ devConfig.cookie.userLastName,
+ req.headers[devConfig.cookie.userLastName] || userType.lastName
+ );
if (
- proxyRes.statusCode === 302 &&
- proxyRes.headers.location.indexOf(devConfig.proxyConfig.login) >
- -1
+ proxyRes &&
+ proxyRes.headers &&
+ proxyRes.headers.location &&
+ proxyRes.headers.location.indexOf('login') > -1
) {
proxyRes.headers.location = `http://localhost:${devPort}/${
devConfig.proxyConfig.redirectionPath
- }`;
- let myCookies = [];
- for (let cookie in cookies) {
- myCookies.push(cookie + '=' + cookies[cookie]);
- }
- res.setHeader('Set-Cookie', myCookies);
+ }`;
}
}
};
@@ -45,15 +59,17 @@ module.exports = function(server) {
devConfig.proxyConfig.urlReplaceRules.forEach(function(rule) {
if (req.url.indexOf(rule.url) > -1) {
req.url = req.url.replace(rule.replace, rule.with);
+ next();
}
});
devConfig.proxyConfig.jsReplaceRules.forEach(function(rule) {
let regex = new RegExp('^(.*)' + rule.replace);
let match = req.url.match(regex);
- let newUrl = match && match[1] + rule.with + '.js';
+ let newUrl = match && match[1] + rule.with;
if (newUrl) {
console.log(`REWRITING URL: ${req.url} -> ${newUrl}`);
req.url = newUrl;
+ next();
}
});
next();
@@ -80,32 +96,39 @@ module.exports = function(server) {
config: devConfig.proxyConfig.catalogProxy
});
proxies.forEach(function(p) {
+ console.log(
+ 'adding: ' + p.target + ' with rewrite: ' + p.config.rewrite
+ );
middlewares.push(
proxy(
p.config.proxy,
Object.assign({}, proxyConfigDefaults, {
target: p.target,
+ loglevel: 'debug',
pathRewrite: p.config.rewrite
})
)
);
});
- let websocketTarget = devConfig.proxyCatalogTarget;
- if (devConfig.proxyWebsocketTarget) {
- websocketTarget = devConfig.proxyWebsocketTarget;
+ if (devConfig.proxyConfig.websocketProxy.enabled) {
+ let websocketTarget = devConfig.proxyCatalogTarget;
+ if (devConfig.proxyWebsocketTarget) {
+ websocketTarget = devConfig.proxyWebsocketTarget;
+ }
+ console.log('Websocket proxy set to : ' + websocketTarget);
+ console.log('---------------------');
+ var wsProxy = proxy(
+ devConfig.proxyConfig.websocketProxy.proxy,
+ Object.assign({}, proxyConfigDefaults, {
+ target: websocketTarget,
+ ws: true
+ })
+ );
+ middlewares.push(wsProxy);
+ server.use(middlewares);
+ server.on('upgrade', wsProxy.upgrade);
+ } else {
+ server.use(middlewares);
}
- console.log('Websocket proxy set to : ' + websocketTarget);
- console.log('---------------------');
- var wsProxy = proxy(
- devConfig.proxyConfig.websocketProxy.proxy,
- Object.assign({}, proxyConfigDefaults, {
- target: websocketTarget,
- ws: true
- })
- );
- middlewares.push(wsProxy);
-
- server.use(middlewares);
- server.on('upgrade', wsProxy.upgrade);
};