Skip to content

Commit 5a17c8b

Browse files
committed
refactor: Use environment variables for backend endpoint
Instead of hardcoding in backend endpoints in the front-end use environemnt variables setup suggest by next.js. Makes it easier to switch endpoints on-the-fly in dev, test prod
1 parent 6a7e3b9 commit 5a17c8b

File tree

7 files changed

+9
-5
lines changed

7 files changed

+9
-5
lines changed

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.9.0

front/.env.development

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PUBLIC_BACKEND_HOST=http://localhost:5000

front/.env.production

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PUBLIC_BACKEND_HOST=http://localhost:5000

front/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front/src/app/api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import createAPI from "@/lib/api";
22

33
const api = createAPI({
4-
baseURL: "http://localhost:5000",
4+
baseURL: `${process.env.NEXT_PUBLIC_BACKEND_HOST}`,
55
withCredentials: true,
66
});
77

front/src/lib/api/common.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { z } from "zod";
44

55
import { GetManySchema } from "@/lib/schemas";
66

7-
export const HOST = "http://localhost:5000";
7+
export const HOST = `${process.env.NEXT_PUBLIC_BACKEND_HOST}`;
88
export const BASE_ROUTE = `/api/v1`;
99

10+
1011
export const instance = axios.create({
1112
withCredentials: true,
1213
baseURL: HOST,

front/src/lib/api/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type APIConfig = {
3636
};
3737

3838
const DEFAULT_CONFIG: APIConfig = {
39-
baseURL: "http://localhost:5000",
39+
baseURL: `${process.env.NEXT_PUBLIC_BACKEND_HOST}`,
4040
withCredentials: true,
4141
};
4242

0 commit comments

Comments
 (0)