diff --git a/README.md b/README.md index 6c824694..7930a817 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ Prerequisite: golang installed Prerequisite: bun installed -The environment variables `BASE_URL` and `AUTH_HOST` will need to be set for the middleware. +The environment variables `API_HOST` and `AUTH_HOST` will need to be set for the middleware. Example `.env` in web's root: ``` -BASE_URL="http://localhost:8082/" +API_HOST="http://localhost:8082/" AUTH_HOST="http://localhost:8083/" ``` diff --git a/web/src/middleware.ts b/web/src/middleware.ts index 4bdf6cc4..61da1048 100644 --- a/web/src/middleware.ts +++ b/web/src/middleware.ts @@ -8,11 +8,11 @@ export function middleware(request: NextRequest) { const { pathname, search } = request.nextUrl if (pathname.startsWith("/api")) { - if (!process.env.BASE_URL) { - throw new Error('env variable "BASE_URL" is not set') + if (!process.env.API_HOST) { + throw new Error('env variable "API_HOST" is not set') } - - const baseUrl = process.env.BASE_URL.replace(/\/$/, ""); + + const baseUrl = process.env.API_HOST.replace(/\/$/, ""); const apiUrl = new URL(baseUrl + pathname + search); return NextResponse.rewrite(apiUrl, { request }); @@ -20,13 +20,13 @@ export function middleware(request: NextRequest) { if (!process.env.AUTH_HOST) { throw new Error('env variable "AUTH_HOST" is not set') } - + const authHost = process.env.AUTH_HOST.replace(/\/$/, ""); const path = pathname.replace(/^\/auth/, ""); const redirectUrl = new URL(authHost + path + search); return NextResponse.redirect(redirectUrl, 302); - } + } return NextResponse.next() -} \ No newline at end of file +}