From bdebb9d44161e1be9cf733d806194fe983817449 Mon Sep 17 00:00:00 2001 From: Weves Date: Wed, 17 May 2023 15:48:46 -0700 Subject: [PATCH] Fix dev setup --- deployment/docker-compose.dev.yml | 3 ++- deployment/docker-compose.prod.yml | 3 ++- web/Dockerfile | 4 +++- web/next.config.js | 28 ++++++++++++++-------------- web/src/lib/constants.ts | 1 + web/src/lib/userSS.ts | 8 +++----- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/deployment/docker-compose.dev.yml b/deployment/docker-compose.dev.yml index 5c91d9c73..472817a5c 100644 --- a/deployment/docker-compose.dev.yml +++ b/deployment/docker-compose.dev.yml @@ -42,7 +42,8 @@ services: env_file: - .env environment: - - INTERNAL_AUTH_URL=http://api_server:8080 + - INTERNAL_URL=http://api_server:8080 + - NODE_ENV=development ports: - "3000:3000" relational_db: diff --git a/deployment/docker-compose.prod.yml b/deployment/docker-compose.prod.yml index 04280da06..45c1978cc 100644 --- a/deployment/docker-compose.prod.yml +++ b/deployment/docker-compose.prod.yml @@ -40,7 +40,8 @@ services: env_file: - .env environment: - - INTERNAL_AUTH_URL=http://api_server:8080 + - INTERNAL_URL=http://api_server:8080 + - NODE_ENV=production relational_db: image: postgres:15.2-alpine restart: always diff --git a/web/Dockerfile b/web/Dockerfile index 9baf3bea6..99d7a8287 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -31,7 +31,9 @@ RUN npm run build FROM base AS runner WORKDIR /app -ENV NODE_ENV production +# Not needed, set by compose +# ENV NODE_ENV production + # Disable automatic telemetry collection ENV NEXT_TELEMETRY_DISABLED 1 diff --git a/web/next.config.js b/web/next.config.js index 93c48a2e3..2ff1e0f40 100644 --- a/web/next.config.js +++ b/web/next.config.js @@ -5,20 +5,20 @@ const nextConfig = { }, output: "standalone", redirects: async () => { - // In production, something else (nginx in the one box setup) takes care - // of this redirect - // NOTE: this may get adjusted later if we want to support hosting of the - // API server on a different domain without requring some kind of proxy - if (process.env.NODE_ENV === "development") { - return [ - { - source: "/api/:path*", - destination: "http://localhost:8080/:path*", // Proxy to Backend - permanent: true, - }, - ]; - } - return []; + // In production, something else (nginx in the one box setup) should take + // care of this redirect. Leaving in for now due to issues with dev setup + // and accessing `process.env.NODE_ENV` + for cases where people don't want + // to setup nginx and are okay with the frontend proxying the request. + // TODO (chris): better support non-nginx setups + return [ + { + source: "/api/:path*", + destination: `${ + process.env.INTERNAL_URL || "http://localhost:8080" + }/:path*`, // Proxy to Backend + permanent: true, + }, + ]; }, }; diff --git a/web/src/lib/constants.ts b/web/src/lib/constants.ts index 2b64832e3..1c54c7269 100644 --- a/web/src/lib/constants.ts +++ b/web/src/lib/constants.ts @@ -1 +1,2 @@ export const DISABLE_AUTH = process.env.DISABLE_AUTH?.toLowerCase() === "true"; +export const INTERNAL_URL = process.env.INTERNAL_URL || "http://127.0.0.1:8080"; diff --git a/web/src/lib/userSS.ts b/web/src/lib/userSS.ts index 8245cf465..628cb5a2d 100644 --- a/web/src/lib/userSS.ts +++ b/web/src/lib/userSS.ts @@ -1,14 +1,12 @@ import { cookies } from "next/headers"; import { User } from "./types"; - -const INTERNAL_AUTH_URL = - process.env.INTERNAL_AUTH_URL || "http://127.0.0.1:8080"; +import { INTERNAL_URL } from "./constants"; export const buildUrl = (path: string) => { if (path.startsWith("/")) { - return `${INTERNAL_AUTH_URL}${path}`; + return `${INTERNAL_URL}${path}`; } - return `${INTERNAL_AUTH_URL}/${path}`; + return `${INTERNAL_URL}/${path}`; }; export const getGoogleOAuthUrlSS = async (): Promise => {