Copilot commented on code in PR #360:
URL:
https://github.com/apache/kvrocks-controller/pull/360#discussion_r2413386002
##########
webui/src/middleware.ts:
##########
@@ -0,0 +1,20 @@
+import { NextResponse } from "next/server";
+import type { NextRequest } from "next/server";
+
+export function middleware(req: NextRequest) {
+ const url = req.nextUrl.clone()
+
+ if (url.pathname.startsWith("/api/v1")) {
+ const host = process.env.KVCTL_API_HOST || "localhost:9379"
+ url.host = host;
Review Comment:
Setting `url.host` directly may not work correctly if KVCTL_API_HOST
contains a port. Consider parsing the host and port separately or using
`url.hostname` and `url.port` properties to handle cases where the environment
variable includes both host and port.
```suggestion
const [hostname, port] = host.split(":");
url.hostname = hostname;
url.port = port || "";
```
##########
webui/src/middleware.ts:
##########
@@ -0,0 +1,20 @@
+import { NextResponse } from "next/server";
+import type { NextRequest } from "next/server";
+
+export function middleware(req: NextRequest) {
+ const url = req.nextUrl.clone()
+
+ if (url.pathname.startsWith("/api/v1")) {
+ const host = process.env.KVCTL_API_HOST || "localhost:9379"
+ url.host = host;
+
+ return NextResponse.rewrite(url)
+ }
+
+ return NextResponse.next()
+}
+
+export const config = {
+ matcher: "/api/v1/:path*",
Review Comment:
The matcher pattern only covers `/api/v1` but the middleware function checks
for `url.pathname.startsWith('/api/v1')`. Consider aligning these patterns or
using a more specific matcher like `'/api/v1/:path*'` to ensure consistency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]