next public env prefix (#82)

This commit is contained in:
Brace Sproul
2024-03-21 13:11:28 -07:00
committed by GitHub
parent f400fa4209
commit d86b5614fd
4 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ jobs:
name: Build frontend
runs-on: ubuntu-latest
env:
BASE_API_URL: http://localhost:8000
NEXT_PUBLIC_BASE_API_URL: http://localhost:8000
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18.x
+1 -1
View File
@@ -1,3 +1,3 @@
# Only set for non development builds.
# Development builds default to `http://localhost:8000`
BASE_API_URL=https://example.com
NEXT_PUBLIC_BASE_API_URL=https://example.com
+5 -3
View File
@@ -2,8 +2,10 @@ export const getBaseApiUrl = () => {
if (process.env.NODE_ENV === "development") {
return "http://localhost:8000";
}
if (!process.env.BASE_API_URL) {
throw new Error("BASE_API_URL must be set if not in development.");
if (!process.env.NEXT_PUBLIC_BASE_API_URL) {
throw new Error(
"NEXT_PUBLIC_BASE_API_URL must be set if not in development.",
);
}
return process.env.BASE_API_URL;
return process.env.NEXT_PUBLIC_BASE_API_URL;
};
+3 -1
View File
@@ -12,7 +12,9 @@ export function middleware(request: NextRequest) {
const userId = request.cookies.get(USER_ID_COOKIE_KEY);
if (!userId) {
response.cookies.set(USER_ID_COOKIE_KEY, uuidv4());
response.cookies.set(USER_ID_COOKIE_KEY, uuidv4(), {
});
}
return response;
}