diff --git a/docker-compose.yml b/docker-compose.yml index 7d9e91625a..fe7770e661 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -99,8 +99,8 @@ services: command: - | yarn install --immutable - yarn workspace mit-learn storybook --no-open & - yarn workspace mit-learn watch:docker + yarn workspace ol-components storybook --no-open & + yarn watch env_file: - path: env/shared.env - path: env/shared.local.env @@ -116,6 +116,10 @@ services: - "6006:6006" volumes: - .:/src + environment: + - NEXT_SERVER_MITOL_API_BASE_URL=http://nginx:8063/ + links: + - web celery: profiles: diff --git a/env/frontend.env b/env/frontend.env index 4a57fe35a0..1781f81d48 100644 --- a/env/frontend.env +++ b/env/frontend.env @@ -1,4 +1,12 @@ NODE_ENV=development PORT=8062 -MITOL_AXIOS_WITH_CREDENTIALS=true -SENTRY_ENV=dev +SENTRY_ENV=dev # Re-enable sentry + +# Environment variables with `NEXT_PUBLIC_` prefix are exposed to the client side +NEXT_PUBLIC_ORIGIN=${MITOL_APP_BASE_URL} +NEXT_PUBLIC_MITOL_API_BASE_URL=${MITOL_API_BASE_URL} +NEXT_PUBLIC_CSRF_COOKIE_NAME=${CSRF_COOKIE_NAME} +NEXT_PUBLIC_MITOL_SUPPORT_EMAIL=${MITOL_SUPPORT_EMAIL} + +NEXT_PUBLIC_SITE_NAME="MIT Learn" +NEXT_PUBLIC_MITOL_AXIOS_WITH_CREDENTIALS=true diff --git a/env/frontend.local.example.env b/env/frontend.local.example.env index e69de29bb2..447d7ea82c 100644 --- a/env/frontend.local.example.env +++ b/env/frontend.local.example.env @@ -0,0 +1 @@ +NEXT_PUBLIC_EMBEDLY_KEY="" diff --git a/env/shared.env b/env/shared.env index e22219b661..82a3653e03 100644 --- a/env/shared.env +++ b/env/shared.env @@ -1,5 +1,5 @@ -MITOL_API_BASE_URL=http://api.open.odl.local:8063 MITOL_APP_BASE_URL=http://open.odl.local:8062 +MITOL_API_BASE_URL=http://api.open.odl.local:8063 MITOL_SUPPORT_EMAIL=support@localhost CSRF_COOKIE_NAME=csrftoken-local diff --git a/frontends/api/src/clients.ts b/frontends/api/src/clients.ts index fb1caf9292..1d63bba663 100644 --- a/frontends/api/src/clients.ts +++ b/frontends/api/src/clients.ts @@ -24,7 +24,13 @@ import { import axiosInstance from "./axios" -const MITOL_API_BASE_URL = process.env.NEXT_PUBLIC_MITOL_API_BASE_URL +const IS_SERVER = typeof window === "undefined" +const MITOL_API_BASE_URL = IS_SERVER + ? // NEXT_SERVER_MITOL_API_BASE_URL is generally only needed for local-dev + // in docker, where the client and server make API calls to different hosts + (process.env.NEXT_SERVER_MITOL_API_BASE_URL ?? + process.env.NEXT_PUBLIC_MITOL_API_BASE_URL) + : process.env.NEXT_PUBLIC_MITOL_API_BASE_URL const BASE_PATH = MITOL_API_BASE_URL?.replace(/\/+$/, "") ?? "" diff --git a/frontends/main/.env.example b/frontends/main/.env.example deleted file mode 100644 index 773f5980ab..0000000000 --- a/frontends/main/.env.example +++ /dev/null @@ -1,9 +0,0 @@ -NEXT_PUBLIC_ORIGIN=http://open.odl.local:8062 -NEXT_PUBLIC_MITOL_API_BASE_URL=http://open.odl.local:8063 - -NEXT_PUBLIC_PUBLIC_URL=/ -NEXT_PUBLIC_SITE_NAME=MIT Learn -NEXT_PUBLIC_MITOL_SUPPORT_EMAIL=mitlearn-support@mit.edu -NEXT_PUBLIC_EMBEDLY_KEY= -NEXT_PUBLIC_MITOL_AXIOS_WITH_CREDENTIALS=true -NEXT_PUBLIC_CSRF_COOKIE_NAME=csrftoken-local # Must match CSRF_COOKIE_NAME on the backend's environment diff --git a/frontends/main/src/components/MITLogoLink/MITLogoLink.tsx b/frontends/main/src/components/MITLogoLink/MITLogoLink.tsx index 04989199ca..25ed9647cc 100644 --- a/frontends/main/src/components/MITLogoLink/MITLogoLink.tsx +++ b/frontends/main/src/components/MITLogoLink/MITLogoLink.tsx @@ -2,9 +2,6 @@ import React from "react" import Image from "next/image" import defaultLogo from "../../../public/mit-logo-learn.svg" -const PUBLIC_URL = process.env.NEXT_PUBLIC_PUBLIC_URL -const HOME_URL = `${PUBLIC_URL}/` - interface Props { href?: string className?: string @@ -13,7 +10,7 @@ interface Props { const MITLogoLink: React.FC = ({ href, logo, className }) => ( ({ display: "flex", flexDirection: "column", @@ -162,7 +159,7 @@ const Footer: FunctionComponent = () => { - +