Skip to content

Commit f70497d

Browse files
jortelDvoraShechter1
authored andcommitted
✨ Add /kai reverse-proxy route. (konveyor#2089)
Related: konveyor/tackle2-hub#750 Signed-off-by: Jeff Ortel <jortel@redhat.com>
1 parent 37748ba commit f70497d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

common/src/proxies.ts

+31
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,35 @@ export const proxyMap: Record<string, Options> = {
6060
}
6161
},
6262
},
63+
64+
"/kai": {
65+
target: KONVEYOR_ENV.TACKLE_HUB_URL || "http://localhost:9002",
66+
logLevel: process.env.DEBUG ? "debug" : "info",
67+
68+
changeOrigin: true,
69+
pathRewrite: {
70+
"^/kai": "/services/kai",
71+
},
72+
73+
onProxyReq: (proxyReq, req, _res) => {
74+
// Add the Bearer token to the request if it is not already present, AND if
75+
// the token is part of the request as a cookie
76+
if (req.cookies?.keycloak_cookie && !req.headers["authorization"]) {
77+
proxyReq.setHeader(
78+
"Authorization",
79+
`Bearer ${req.cookies.keycloak_cookie}`
80+
);
81+
}
82+
},
83+
onProxyRes: (proxyRes, req, res) => {
84+
const includesJsonHeaders =
85+
req.headers.accept?.includes("application/json");
86+
if (
87+
(!includesJsonHeaders && proxyRes.statusCode === 401) ||
88+
(!includesJsonHeaders && proxyRes.statusMessage === "Unauthorized")
89+
) {
90+
res.redirect("/");
91+
}
92+
},
93+
},
6394
};

0 commit comments

Comments
 (0)