From 76df6f66d965dd751146468abfafb0c6acd46310 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Tue, 23 Jan 2024 15:22:08 +0100 Subject: [PATCH] fix: replace middleware backend url with local backend url --- README.md | 1 + frontend/src/middleware.ts | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 974d1a2..44cc43c 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ pm2 start --name="pingvin-share-backend" npm -- run prod cd ../frontend npm install npm run build +API_URL=http://localhost:8080 # Set the URL of the backend, default: http://localhost:8080 pm2 start --name="pingvin-share-frontend" npm -- run start ``` diff --git a/frontend/src/middleware.ts b/frontend/src/middleware.ts index cc9d1eb..9b9af19 100644 --- a/frontend/src/middleware.ts +++ b/frontend/src/middleware.ts @@ -21,9 +21,8 @@ export async function middleware(request: NextRequest) { }; // Get config from backend - const config = await ( - await fetch(`${request.nextUrl.origin}/api/configs`) - ).json(); + const apiUrl = process.env.API_URL || "http://localhost:8080"; + const config = await (await fetch(`${apiUrl}/api/configs`)).json(); const getConfig = (key: string) => { return configService.get(key, config); @@ -35,7 +34,7 @@ export async function middleware(request: NextRequest) { try { const claims = jwtDecode<{ exp: number; isAdmin: boolean }>( - accessToken as string, + accessToken as string ); if (claims.exp * 1000 > Date.now()) { user = claims;