Skip to content

Commit

Permalink
✨ Add /kai reverse-proxy route. (konveyor#2089)
Browse files Browse the repository at this point in the history
Related: konveyor/tackle2-hub#750

Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel authored and DvoraShechter1 committed Oct 28, 2024
1 parent b7616e6 commit 0ad6fae
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions common/src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,35 @@ export const proxyMap: Record<string, Options> = {
}
},
},

"/kai": {
target: KONVEYOR_ENV.TACKLE_HUB_URL || "http://localhost:9002",
logLevel: process.env.DEBUG ? "debug" : "info",

changeOrigin: true,
pathRewrite: {
"^/kai": "/services/kai",
},

onProxyReq: (proxyReq, req, _res) => {
// Add the Bearer token to the request if it is not already present, AND if
// the token is part of the request as a cookie
if (req.cookies?.keycloak_cookie && !req.headers["authorization"]) {
proxyReq.setHeader(
"Authorization",
`Bearer ${req.cookies.keycloak_cookie}`
);
}
},
onProxyRes: (proxyRes, req, res) => {
const includesJsonHeaders =
req.headers.accept?.includes("application/json");
if (
(!includesJsonHeaders && proxyRes.statusCode === 401) ||
(!includesJsonHeaders && proxyRes.statusMessage === "Unauthorized")
) {
res.redirect("/");
}
},
},
};

0 comments on commit 0ad6fae

Please sign in to comment.