Cut the edge over from nginx and certbot to Caddy
Caddy takes nginx's place in compose: ports 80/443, the fixed address 172.28.255.251 that cloudflared pins the public names to, the network aliases, the healthcheck and the autoheal label. nginx and certbot are removed from compose; Caddy already holds its own certificates in ./caddy/data, obtained while it ran beside nginx. `traffic` now tails logs/caddy/payloads.log, and the dev override switches Caddy to its dev sites instead of putting nginx in DEV_MODE. Docs and comments that described nginx's behaviour now describe Caddy's: CLAUDE.md, DEPLOYMENT.md (topology, boot paths, TLS, rate limits, runbook with a rollback, rough edges), the READMEs, .env.example and the comments in the backend, Python service, Vue source and infra files. nginx/ and certbot/ stay in the repo as the rollback until this has settled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
# Vue frontend image — builds the SPA.
|
||||
#
|
||||
# THIS IS A BUILD CONTAINER, NOT A SERVER. In production the container runs
|
||||
# `vite build` into /output (the shared vue_dist volume) and EXITS. nginx then
|
||||
# `vite build` into /output (the shared vue_dist volume) and EXITS. Caddy then
|
||||
# serves those files. Seeing `vue` as Exited(0) in `docker compose ps` is the
|
||||
# success case, not a failure. The dev override replaces the CMD with the Vite
|
||||
# dev server, and then it does stay running.
|
||||
|
||||
+13
-13
@@ -14,7 +14,7 @@ npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
The Vite dev server stands in for nginx and proxies four prefixes. Each target
|
||||
The Vite dev server stands in for Caddy and proxies four prefixes. Each target
|
||||
is an environment variable, read in `vite.config.js` from the shell or from
|
||||
`vue/.env.local`:
|
||||
|
||||
@@ -22,11 +22,11 @@ is an environment variable, read in `vite.config.js` from the shell or from
|
||||
| --- | --- | --- | --- |
|
||||
| `/api` | `VITE_PROXY_API` | `http://localhost:8080` | Go backend |
|
||||
| `/gitea` | `VITE_PROXY_GITEA` | `http://localhost:3000` | Gitea |
|
||||
| `/py` | `VITE_PROXY_PY` | `http://localhost:8000` | FastAPI (the `/py` prefix is stripped, as nginx does in production) |
|
||||
| `/py` | `VITE_PROXY_PY` | `http://localhost:8000` | FastAPI (the `/py` prefix is stripped, as Caddy does in production) |
|
||||
| `/radio` | `VITE_PROXY_RADIO` | `http://localhost:8000` | Icecast2 |
|
||||
|
||||
**The defaults are not "where the compose stack is".** The stack publishes only
|
||||
nginx (80/443), Gitea (3000) and the liquidsoap harbor port to the host; the
|
||||
Caddy (80/443), Gitea (3000) and the liquidsoap harbor port to the host; the
|
||||
backend, the Python service and Icecast are reachable only inside the Docker
|
||||
network. The defaults are each service's own port, i.e. where it listens when
|
||||
you run it directly on the host (`go run .`, `uvicorn app.main:app`). `/py` and
|
||||
@@ -34,10 +34,10 @@ you run it directly on the host (`go run .`, `uvicorn app.main:app`). `/py` and
|
||||
can be right at a time — normally `/py`, with the radio simply reading as
|
||||
offline.
|
||||
|
||||
To use a running compose stack instead, point the prefix at its nginx, e.g.
|
||||
To use a running compose stack instead, point the prefix at its Caddy, e.g.
|
||||
`VITE_PROXY_API=http://localhost npm run dev`. That works for `/api`, `/gitea`
|
||||
and `/radio`, which are forwarded with the path intact. It does not work for
|
||||
`/py`, because the proxy strips the prefix nginx routes on — `VITE_PROXY_PY`
|
||||
`/py`, because the proxy strips the prefix Caddy routes on — `VITE_PROXY_PY`
|
||||
has to be a bare uvicorn.
|
||||
|
||||
## Structure
|
||||
@@ -66,10 +66,10 @@ Two layout shells, defined in `src/router/index.js`:
|
||||
| `/` | DefaultLayout | Landing page (statically imported — it's the first paint): a box canvas, page key `index`; the old fixed page is its starter layout, `views/landing/landingLayout.js` |
|
||||
| `/stp` | DefaultLayout | The personal home page: an ordinary canvas page (the `Page` with slug `stp`) served by the catch-all, see "The /stp canvas" below |
|
||||
| `/admin`, `/admin/login` | DefaultLayout | `/admin` is guarded by `meta.requiresAdmin`. The login page is everyone's, admin or not |
|
||||
| `/account`, `/no-access` | DefaultLayout | `views/account/Account.vue`, guarded by `meta.requiresSignIn`: the gated services a non-admin has been granted. `/no-access` is where nginx's permission gate sends a signed-in visitor without the grant |
|
||||
| `/account`, `/no-access` | DefaultLayout | `views/account/Account.vue`, guarded by `meta.requiresSignIn`: the gated services a non-admin has been granted. `/no-access` is where Caddy's permission gate sends a signed-in visitor without the grant |
|
||||
| `/automata`, `/hotels` | DefaultLayout | |
|
||||
| `/shrines`, `/shrines/*` | DefaultLayout | All canvas pages via the catch-all: `/shrines` is an index whose links are Link boxes placed by hand |
|
||||
| `/cv` | CVLayout | Light print theme. Its Jobs button goes to `/jobs/`, the separate job tracker app (`adamf/job-tracker`); nginx redirects the old `/cv/jobs` and `/cv/leads` there |
|
||||
| `/cv` | CVLayout | Light print theme. Its Jobs button goes to `/jobs/`, the separate job tracker app (`adamf/job-tracker`); Caddy redirects the old `/cv/jobs` and `/cv/leads` there |
|
||||
| `/stp2` | (none) | Bare full-bleed mock, deliberately outside both layouts |
|
||||
| `:pathMatch(.*)*` | DefaultLayout | `views/canvas/CanvasPage.vue`: an admin-created canvas page if one exists at the path, else the 404 (with a "create a page here" form for admins) |
|
||||
|
||||
@@ -118,7 +118,7 @@ const data = await gql(`query { ... }`, variables);
|
||||
|
||||
It POSTs to `/api/graphql` and throws on an error response with no data. Auth
|
||||
rides along in **HTTP-only cookies** set by the Go backend, so nothing here
|
||||
touches tokens — the request just has to be same-origin (nginx in production,
|
||||
touches tokens — the request just has to be same-origin (Caddy in production,
|
||||
the Vite proxy in dev).
|
||||
|
||||
The backend's REST routes go through `src/api.js`, the same idea for plain JSON:
|
||||
@@ -240,7 +240,7 @@ renders any page's boxes.
|
||||
(`Home3.vue`, now legacy), and the backend creates its `Page` row once at
|
||||
start-up (`ensureStpPage` in `backend/services/database.go`), so it can be
|
||||
renamed, hidden or deleted like any other.
|
||||
The server refuses slugs that an SPA or nginx route would answer first
|
||||
The server refuses slugs that an SPA or Caddy route would answer first
|
||||
(`validateSlug` in `backend/graph/page_helpers.go`) — add to that list when
|
||||
adding a route.
|
||||
- **Backgrounds.** Each page key can have its own background (`Background` in
|
||||
@@ -357,10 +357,10 @@ renders any page's boxes.
|
||||
|
||||
- **Dev** (`npm run dev`): Vite serves the SPA and proxies `/api`, `/gitea`,
|
||||
`/radio` and `/py` to the `VITE_PROXY_*` targets (see Development above and
|
||||
`vite.config.js`). The `/py` proxy strips the prefix, matching what nginx
|
||||
`vite.config.js`). The `/py` proxy strips the prefix, matching what Caddy
|
||||
does in production.
|
||||
- **Production** (`npm run build`): `dist/` is built into the nginx container
|
||||
and served as static files, with nginx doing the same reverse-proxying.
|
||||
- **Production** (`npm run build`): `dist/` is written into the `vue_dist`
|
||||
volume and served as static files by Caddy, which does the same reverse-proxying.
|
||||
|
||||
`npm run build` is a plain `vite build`. It is also the local check that the
|
||||
app still compiles — there is no test runner or linter.
|
||||
@@ -438,7 +438,7 @@ Note that Tailwind's spacing unit is set to **3px** (not the default 4px), so `p
|
||||
npm run build
|
||||
```
|
||||
|
||||
In production, the built `dist/` is served by Nginx inside a Docker container (see `../Dockerfile`).
|
||||
In production, the built `dist/` is served by Caddy from the `vue_dist` volume (see `../Dockerfile` and `../../caddy/`).
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* Auth rides along in HTTP-only cookies set by the backend, so no token handling
|
||||
* is needed here — axios sends them automatically because the request is
|
||||
* same-origin (nginx in production, the Vite proxy in dev).
|
||||
* same-origin (Caddy in production, the Vite proxy in dev).
|
||||
*/
|
||||
|
||||
import axios from "axios";
|
||||
|
||||
@@ -46,7 +46,7 @@ const router = createRouter({
|
||||
},
|
||||
// A signed-in user's own page: the gated services they have
|
||||
// been granted. /no-access is the same page with a notice,
|
||||
// where nginx's permission gate sends a refused visitor.
|
||||
// where Caddy's permission gate sends a refused visitor.
|
||||
{
|
||||
path: "account",
|
||||
name: "account",
|
||||
@@ -105,7 +105,7 @@ const router = createRouter({
|
||||
component: () => import("@/views/CV/CV.vue"),
|
||||
},
|
||||
// /cv/jobs and /cv/leads moved to the job tracker app at
|
||||
// /jobs/; nginx redirects the old paths.
|
||||
// /jobs/; Caddy redirects the old paths.
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -18,7 +18,7 @@ import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
/**
|
||||
* Same-origin ws:// or wss:// URL for the chat socket, derived from the page's
|
||||
* own protocol and host. Nothing is configurable: nginx (prod) and the Vite
|
||||
* own protocol and host. Nothing is configurable: Caddy (prod) and the Vite
|
||||
* proxy (dev) both serve /api/ws from the same origin as the page, and the
|
||||
* auth cookies only travel if the origin matches.
|
||||
*/
|
||||
@@ -171,7 +171,7 @@ export const useMessagesStore = defineStore("messages", () => {
|
||||
* surface via `lastError`.
|
||||
*
|
||||
* `private` goes to both: the upload is stored under /uploads/private/,
|
||||
* which nginx gates behind an admin check, and the message is marked
|
||||
* which Caddy gates behind an admin check, and the message is marked
|
||||
* private. The two must agree.
|
||||
*/
|
||||
async function uploadAndSendFile(file, isPrivate = false) {
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* page for a signed-in account that is not an admin, listing the gated
|
||||
* services it has been granted (backend/services/permissions.go) as links.
|
||||
*
|
||||
* `/no-access` is where nginx's permission gate sends a signed-in visitor who
|
||||
* `/no-access` is where Caddy's permission gate sends a signed-in visitor who
|
||||
* lacks the permission (`@auth_forbidden`, with the refused address in
|
||||
* `?path=`). It is this same page with a notice on top, since "what can I
|
||||
* open instead" is the useful answer to "you can't open that".
|
||||
*
|
||||
* The links are plain <a href>, not RouterLinks: every service lives in
|
||||
* another container behind nginx, so it needs a real page load.
|
||||
* another container behind Caddy, so it needs a real page load.
|
||||
*/
|
||||
import { ref, computed, onMounted } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
@@ -98,7 +98,7 @@ async function handleLogout() {
|
||||
{{ section.label }}
|
||||
</button>
|
||||
<!-- Logs and incoming request bodies live in Dozzle, outside the
|
||||
SPA (nginx serves it at /dozzle/ behind the admin check). -->
|
||||
SPA (Caddy serves it at /dozzle/ behind the admin check). -->
|
||||
<a
|
||||
class="admin-nav-link no-underline"
|
||||
href="/dozzle/"
|
||||
@@ -108,7 +108,7 @@ async function handleLogout() {
|
||||
Logs ↗
|
||||
</a>
|
||||
<!-- The receipt printer's page is served from stppi, which reaches
|
||||
the printer on the home LAN; nginx proxies /receipt/ there over
|
||||
the printer on the home LAN; Caddy proxies /receipt/ there over
|
||||
Tailscale behind the `receipt` permission gate. -->
|
||||
<a
|
||||
class="admin-nav-link no-underline"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* (a non-admin would only bounce off /admin's guard back to here).
|
||||
*
|
||||
* The `?redirect=` is set by two different gates: the SPA router guard
|
||||
* (`meta.requiresAdmin`) and nginx's `auth_request` gate in front of the
|
||||
* (`meta.requiresAdmin`) and Caddy's `forward_auth` gate in front of the
|
||||
* proxied containers (/notes/, /sb/, /receipt/). The latter means the
|
||||
* destination is frequently NOT a Vue route, so see goTo() below.
|
||||
*
|
||||
@@ -34,12 +34,12 @@ const errorMsg = ref("");
|
||||
|
||||
// Send the browser to `dest`, choosing SPA navigation vs. a real page load.
|
||||
//
|
||||
// nginx bounces /notes/, /sb/, /receipt/ and the like here when the session
|
||||
// Caddy bounces /notes/, /sb/, /receipt/ and the like here when the session
|
||||
// is missing; those paths belong to other containers, so router.push() would just
|
||||
// match the catch-all 404 route and never leave the SPA. Resolving the path
|
||||
// first tells us which it is: the catch-all matches everything, so landing on
|
||||
// the route named "404" means no real Vue route exists and the browser needs a
|
||||
// full document request for nginx to proxy it.
|
||||
// full document request for Caddy to proxy it.
|
||||
//
|
||||
// `dest` comes from the query string, so it is only followed when it is a
|
||||
// site-relative path — a leading "//" or a scheme would be an open redirect.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* site's 404 — with, for an admin, a form to create a page right here.
|
||||
*
|
||||
* Static routes always win, which is why the server refuses slugs under the
|
||||
* SPA's and nginx's own paths (validateSlug in backend/graph/page_helpers.go).
|
||||
* SPA's and Caddy's own paths (validateSlug in backend/graph/page_helpers.go).
|
||||
*
|
||||
* An adminOnly page answers null to anyone else, so to them it is simply a
|
||||
* 404.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* in as literal values, read from the live page so a re-themed layout
|
||||
* (CVLayout re-points the tokens) would carry through.
|
||||
* - Load our fonts. Without allow-same-origin its origin is opaque ("null"),
|
||||
* which makes /fonts/*.woff2 a cross-origin font load that nginx and the
|
||||
* which makes /fonts/*.woff2 a cross-origin font load that Caddy and the
|
||||
* Vite dev server would both refuse without CORS headers. Instead the page
|
||||
* fetches the two files (28 KB) once, same-origin, and inlines them as
|
||||
* data: URLs.
|
||||
|
||||
@@ -58,7 +58,7 @@ export async function runStream(url, body, { signal, onEvent }) {
|
||||
try {
|
||||
payload = await res.json();
|
||||
} catch {
|
||||
/* non-JSON body (e.g. nginx error page) */
|
||||
/* non-JSON body (e.g. an error page from the edge) */
|
||||
}
|
||||
throw new Error(describeError(res.status, payload));
|
||||
}
|
||||
|
||||
+8
-8
@@ -7,11 +7,11 @@ import vueDevTools from "vite-plugin-vue-devtools";
|
||||
|
||||
// Dev-server proxy targets (frontend-only `npm run dev`).
|
||||
//
|
||||
// In production, and in the full compose stack, nginx does this routing. The
|
||||
// In production, and in the full compose stack, Caddy does this routing. The
|
||||
// Vite dev server has to stand in for it, which means reaching each service
|
||||
// FROM THE HOST — and the compose stack publishes almost none of them:
|
||||
//
|
||||
// published by docker-compose.yml: nginx (80/443), gitea (3000 + 2222 ssh),
|
||||
// published by docker-compose.yml: caddy (80/443), gitea (3000 + 2222 ssh),
|
||||
// the liquidsoap harbor port
|
||||
// NOT published: backend (8080), python (8000),
|
||||
// icecast (8000), db, silverbullet
|
||||
@@ -37,9 +37,9 @@ import vueDevTools from "vite-plugin-vue-devtools";
|
||||
// VITE_PROXY_RADIO Icecast default http://localhost:8000
|
||||
//
|
||||
// To borrow a running compose stack instead of running services on the host,
|
||||
// point API / GITEA / RADIO at its nginx (e.g. VITE_PROXY_API=http://localhost):
|
||||
// those three are forwarded with their path intact, which is what nginx
|
||||
// expects. VITE_PROXY_PY cannot be pointed at nginx — see the rewrite below.
|
||||
// point API / GITEA / RADIO at its Caddy (e.g. VITE_PROXY_API=http://localhost):
|
||||
// those three are forwarded with their path intact, which is what Caddy
|
||||
// expects. VITE_PROXY_PY cannot be pointed at Caddy — see the rewrite below.
|
||||
const DEFAULT_PROXY = {
|
||||
VITE_PROXY_API: "http://localhost:8080",
|
||||
VITE_PROXY_GITEA: "http://localhost:3000",
|
||||
@@ -76,9 +76,9 @@ export default defineConfig(({ mode }) => {
|
||||
"/api": env.VITE_PROXY_API,
|
||||
"/gitea": env.VITE_PROXY_GITEA,
|
||||
"/radio": env.VITE_PROXY_RADIO,
|
||||
// Python API: nginx strips the /py prefix in production, so do the
|
||||
// same here. That makes the target a bare uvicorn — pointed at nginx
|
||||
// the request would arrive without the prefix nginx routes on.
|
||||
// Python API: Caddy strips the /py prefix in production, so do the
|
||||
// same here. That makes the target a bare uvicorn — pointed at Caddy
|
||||
// the request would arrive without the prefix Caddy routes on.
|
||||
"/py": {
|
||||
target: env.VITE_PROXY_PY,
|
||||
rewrite: (path) => path.replace(/^\/py/, ""),
|
||||
|
||||
Reference in New Issue
Block a user