forked from StrafesNET/maps-service
env var name change requires deployment configuration change
This commit is contained in:
@@ -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/"
|
||||
```
|
||||
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user