This commit is contained in:
@@ -30,7 +30,10 @@ Environment: `backend/.env` (`PORT=5000`, `MONGO_URI=mongodb://127.0.0.1:27017/m
|
|||||||
`JWT_SECRET` — signs session tokens, `AUTH_TOKEN_TTL` — how long one lasts, default `7d`;
|
`JWT_SECRET` — signs session tokens, `AUTH_TOKEN_TTL` — how long one lasts, default `7d`;
|
||||||
see `.env.example`). Without `JWT_SECRET` the API warns and uses an insecure dev key.
|
see `.env.example`). Without `JWT_SECRET` the API warns and uses an insecure dev key.
|
||||||
Frontend API URL comes from `NUXT_PUBLIC_API_BASE`
|
Frontend API URL comes from `NUXT_PUBLIC_API_BASE`
|
||||||
(default `http://localhost:5000`, read via `runtimeConfig.public.apiBase`).
|
(default `http://localhost:5000`, read via `runtimeConfig.public.apiBase`). The frontend image
|
||||||
|
builds it empty: the browser then calls `/api` on its own origin, which nginx routes to
|
||||||
|
`backend:5000`, while the Nuxt server's own (SSR) `/api` calls go through a `routeRules` proxy
|
||||||
|
aimed at `NUXT_API_PROXY_TARGET` (`http://backend:5000` baked in at image build).
|
||||||
|
|
||||||
There is **no test suite, linter, or typecheck script** configured — don't invent commands.
|
There is **no test suite, linter, or typecheck script** configured — don't invent commands.
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ RUN npm install
|
|||||||
ARG CACHEBUST=1
|
ARG CACHEBUST=1
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# Production API wiring (baked into the build):
|
||||||
|
# - the browser calls /api on its own origin; nginx forwards that to backend:5000
|
||||||
|
# - the Nuxt server (SSR) reaches the backend container by service name
|
||||||
|
ENV NUXT_PUBLIC_API_BASE=
|
||||||
|
ENV NUXT_API_PROXY_TARGET=http://backend:5000
|
||||||
|
|
||||||
# Build the Nuxt app
|
# Build the Nuxt app
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ Handy macros: `\R`, `\N`, `\Z`, `\Q`, `\C` for the number sets.
|
|||||||
| `backend/.env` | `PORT` | `5000` | API port |
|
| `backend/.env` | `PORT` | `5000` | API port |
|
||||||
| `backend/.env` | `MONGO_URI` | `mongodb://127.0.0.1:27017/mathew` | Mongo connection |
|
| `backend/.env` | `MONGO_URI` | `mongodb://127.0.0.1:27017/mathew` | Mongo connection |
|
||||||
| `frontend` env | `NUXT_PUBLIC_API_BASE` | `http://localhost:5000` | Where the UI calls the API |
|
| `frontend` env | `NUXT_PUBLIC_API_BASE` | `http://localhost:5000` | Where the UI calls the API |
|
||||||
|
| `frontend` build | `NUXT_API_PROXY_TARGET` | `http://localhost:5000` | Where the Nuxt server's own (SSR) `/api` calls are forwarded |
|
||||||
|
|
||||||
|
In Docker the frontend image builds with `NUXT_PUBLIC_API_BASE=` (empty): the browser calls
|
||||||
|
`/api` on its own origin and nginx routes it to `http://backend:5000` — the same hop answers
|
||||||
|
the Nuxt server's SSR calls, which the image points at the backend container via
|
||||||
|
`NUXT_API_PROXY_TARGET`.
|
||||||
|
|
||||||
## Editing tips
|
## Editing tips
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,20 @@ export default defineNuxtConfig({
|
|||||||
|
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
public: {
|
public: {
|
||||||
// Override with NUXT_PUBLIC_API_BASE in production
|
// Where the UI calls the API. The Docker image sets this to "" so the
|
||||||
apiBase: process.env.NUXT_PUBLIC_API_BASE || 'http://localhost:5000',
|
// browser calls /api on its own origin and nginx routes it to the
|
||||||
|
// backend; dev keeps the absolute localhost address.
|
||||||
|
apiBase: process.env.NUXT_PUBLIC_API_BASE ?? 'http://localhost:5000',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// The Nuxt server's own API calls (SSR) are relative once apiBase is "",
|
||||||
|
// and land on this Nitro route, which forwards them to the backend. The
|
||||||
|
// Docker image bakes NUXT_API_PROXY_TARGET=http://backend:5000 in at build.
|
||||||
|
routeRules: {
|
||||||
|
'/api/**': { proxy: `${process.env.NUXT_API_PROXY_TARGET || 'http://localhost:5000'}/api/**` },
|
||||||
|
},
|
||||||
|
|
||||||
app: {
|
app: {
|
||||||
head: {
|
head: {
|
||||||
meta: [
|
meta: [
|
||||||
|
|||||||
Reference in New Issue
Block a user