added reverse proxy
This commit is contained in:
parent
afd7fd7686
commit
246b1990ca
57 changed files with 4174 additions and 4139 deletions
15
AGENTS.md
15
AGENTS.md
|
|
@ -5,7 +5,7 @@
|
||||||
- **SvelteKit 2** (SSR, Svelte 5 runes mode) — all `.svelte` files use `$state`, `$derived`, `$props()` etc.
|
- **SvelteKit 2** (SSR, Svelte 5 runes mode) — all `.svelte` files use `$state`, `$derived`, `$props()` etc.
|
||||||
- **PocketBase** — REST API via the `pocketbase` SDK (v0.26). Auth, DB, and image storage.
|
- **PocketBase** — REST API via the `pocketbase` SDK (v0.26). Auth, DB, and image storage.
|
||||||
- **Tailwind CSS v4** + **DaisyUI 5** — utility-first CSS with DaisyUI components for admin; custom theme for the public site.
|
- **Tailwind CSS v4** + **DaisyUI 5** — utility-first CSS with DaisyUI components for admin; custom theme for the public site.
|
||||||
- **Docker Compose** — two services: `app` (SvelteKit) and `pocketbase`.
|
- **Docker Compose** — three services: `app` (SvelteKit), `pocketbase`, and `caddy` (reverse proxy).
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
|
|
@ -88,18 +88,19 @@ npm run build
|
||||||
# Type checking
|
# Type checking
|
||||||
npm run check
|
npm run check
|
||||||
|
|
||||||
# Docker full stack
|
# Docker full stack (single entry point on port 8080)
|
||||||
docker compose up --build
|
docker compose up --build
|
||||||
# App: http://localhost:3000
|
# App + PocketBase via Caddy: http://localhost:8080
|
||||||
# PocketBase admin: http://localhost:8090/_/
|
# PocketBase admin: http://localhost:8080/_/
|
||||||
|
|
||||||
# PocketBase only (for local dev)
|
# PocketBase only (for local dev outside Docker)
|
||||||
docker compose up pocketbase
|
docker compose up pocketbase
|
||||||
|
# Direct access: http://localhost:8090/_/
|
||||||
```
|
```
|
||||||
|
|
||||||
## Environment
|
## Environment
|
||||||
|
|
||||||
- `PUBLIC_POCKETBASE_URL` — public-facing PocketBase URL (default `http://localhost:8090`)
|
- `PUBLIC_POCKETBASE_URL` — public-facing PocketBase URL, now accessed through the Caddy reverse proxy (default `http://localhost:8080`)
|
||||||
- `POCKETBASE_INTERNAL_URL` — internal Docker network URL (`http://pocketbase:80`)
|
- `POCKETBASE_INTERNAL_URL` — internal Docker network URL (`http://pocketbase:80`)
|
||||||
- `ORIGIN` — SvelteKit origin for SSR (`http://localhost:3000`)
|
- `ORIGIN` — SvelteKit origin for SSR (`http://localhost:8080`)
|
||||||
- Copy `app/.env.example` → `app/.env` for local dev
|
- Copy `app/.env.example` → `app/.env` for local dev
|
||||||
|
|
|
||||||
17
Caddyfile
Normal file
17
Caddyfile
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Reverse proxy — single port for both the SvelteKit app and PocketBase
|
||||||
|
# Route: /api/* and /_/* → PocketBase
|
||||||
|
# everything else → SvelteKit app
|
||||||
|
|
||||||
|
:8080 {
|
||||||
|
handle /api/* {
|
||||||
|
reverse_proxy pocketbase:80
|
||||||
|
}
|
||||||
|
|
||||||
|
handle /_/* {
|
||||||
|
reverse_proxy pocketbase:80
|
||||||
|
}
|
||||||
|
|
||||||
|
handle {
|
||||||
|
reverse_proxy app:3000
|
||||||
|
}
|
||||||
|
}
|
||||||
17
README.md
17
README.md
|
|
@ -7,7 +7,7 @@ A full-stack SvelteKit CMS for a single-operator massage studio. PocketBase prov
|
||||||
- SvelteKit + SSR
|
- SvelteKit + SSR
|
||||||
- PocketBase REST API via the `pocketbase` SDK
|
- PocketBase REST API via the `pocketbase` SDK
|
||||||
- Tailwind CSS v4 + DaisyUI
|
- Tailwind CSS v4 + DaisyUI
|
||||||
- Docker Compose with two services: `app` and `pocketbase`
|
- Docker Compose with three services: `app`, `pocketbase`, and `caddy` (reverse proxy)
|
||||||
|
|
||||||
## Local development
|
## Local development
|
||||||
|
|
||||||
|
|
@ -28,6 +28,8 @@ A full-stack SvelteKit CMS for a single-operator massage studio. PocketBase prov
|
||||||
```
|
```
|
||||||
5. Visit `http://localhost:5173`.
|
5. Visit `http://localhost:5173`.
|
||||||
|
|
||||||
|
> **Note:** During local development (outside Docker), PocketBase is accessed directly at `http://localhost:8090`. When running the full Docker stack, everything goes through the Caddy reverse proxy on port `8080`.
|
||||||
|
|
||||||
## Docker Compose
|
## Docker Compose
|
||||||
|
|
||||||
Run the full stack:
|
Run the full stack:
|
||||||
|
|
@ -45,19 +47,20 @@ docker compose up
|
||||||
|
|
||||||
Subsequent builds reuse the npm cache declared in the `Dockerfile`.
|
Subsequent builds reuse the npm cache declared in the `Dockerfile`.
|
||||||
|
|
||||||
- Public SvelteKit app: `http://localhost:3000`
|
- Single entry point (Caddy reverse proxy): **`http://localhost:8080`**
|
||||||
- PocketBase admin UI: `http://localhost:8090/_/`
|
- SvelteKit app: `http://localhost:8080/` (or any non-API path)
|
||||||
|
- PocketBase admin UI: `http://localhost:8080/_/`
|
||||||
|
- PocketBase REST API: `http://localhost:8080/api/`
|
||||||
|
- PocketBase direct access (internal only, not exposed): `http://localhost:8090`
|
||||||
|
|
||||||
The app container uses two PocketBase URLs:
|
The app container uses two PocketBase URLs:
|
||||||
|
|
||||||
- `POCKETBASE_INTERNAL_URL=http://pocketbase:80` for server-side SvelteKit calls from the app container when using the included `spectado/pocketbase` image.
|
- `POCKETBASE_INTERNAL_URL=http://pocketbase:80` for server-side SvelteKit calls from the app container when using the included `spectado/pocketbase` image.
|
||||||
- `PUBLIC_POCKETBASE_URL=http://localhost:8090` for browser-side admin uploads and public file URLs during local Docker development.
|
- `PUBLIC_POCKETBASE_URL=http://localhost:8080` for browser-side admin uploads and public file URLs. Since the Caddy reverse proxy routes `/api/*` to PocketBase, the public URL points to the proxy.
|
||||||
|
|
||||||
In production, set `PUBLIC_POCKETBASE_URL` to the browser-accessible PocketBase URL, or to the reverse-proxied PocketBase path/origin you expose publicly.
|
|
||||||
|
|
||||||
## PocketBase setup
|
## PocketBase setup
|
||||||
|
|
||||||
1. Open `http://localhost:8090/_/`.
|
1. Open `http://localhost:8080/_/` (or `http://localhost:8090/_/` for direct access).
|
||||||
2. Create the first PocketBase admin user when prompted.
|
2. Create the first PocketBase admin user when prompted.
|
||||||
3. Import `pb_schema.json` from the PocketBase admin UI collection settings/import flow. This file uses the newer PocketBase `fields` schema format; if PocketBase still reports `Invalid collections configuration`, create the three collections manually using the fields below.
|
3. Import `pb_schema.json` from the PocketBase admin UI collection settings/import flow. This file uses the newer PocketBase `fields` schema format; if PocketBase still reports `Invalid collections configuration`, create the three collections manually using the fields below.
|
||||||
4. Create starter records:
|
4. Create starter records:
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
PUBLIC_POCKETBASE_URL=http://localhost:8090
|
PUBLIC_POCKETBASE_URL=http://localhost:8080
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { createPocketBase } from '$lib/pb';
|
||||||
export const handle: Handle = async ({ event, resolve }) => {
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
event.locals.pb = createPocketBase(
|
event.locals.pb = createPocketBase(
|
||||||
event.request.headers.get('cookie') ?? '',
|
event.request.headers.get('cookie') ?? '',
|
||||||
env.POCKETBASE_INTERNAL_URL || env.PUBLIC_POCKETBASE_URL || 'http://localhost:8090'
|
env.POCKETBASE_INTERNAL_URL || env.PUBLIC_POCKETBASE_URL || 'http://localhost:8080'
|
||||||
);
|
);
|
||||||
event.locals.user = event.locals.pb.authStore.record;
|
event.locals.user = event.locals.pb.authStore.record;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import PocketBase from 'pocketbase';
|
||||||
import { env } from '$env/dynamic/public';
|
import { env } from '$env/dynamic/public';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
|
|
||||||
export const pbUrl = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8090';
|
export const pbUrl = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8080';
|
||||||
|
|
||||||
export function createPocketBase(authCookie?: string, url = pbUrl) {
|
export function createPocketBase(authCookie?: string, url = pbUrl) {
|
||||||
const pb = new PocketBase(url);
|
const pb = new PocketBase(url);
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||||
formData.append('alt', filename.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' '));
|
formData.append('alt', filename.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' '));
|
||||||
|
|
||||||
const record = await locals.pb.collection('media').create(formData);
|
const record = await locals.pb.collection('media').create(formData);
|
||||||
const publicUrl = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8090';
|
const publicUrl = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8080';
|
||||||
const newUrl = `${publicUrl}/api/files/${record.collectionId}/${record.id}/${record.file}`;
|
const newUrl = `${publicUrl}/api/files/${record.collectionId}/${record.id}/${record.file}`;
|
||||||
|
|
||||||
keyToUrl.set(key, newUrl);
|
keyToUrl.set(key, newUrl);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const record = await locals.pb.collection('media').create(uploadForm);
|
const record = await locals.pb.collection('media').create(uploadForm);
|
||||||
const publicUrl = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8090';
|
const publicUrl = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8080';
|
||||||
const url = `${publicUrl}/api/files/${record.collectionId}/${record.id}/${record.file}`;
|
const url = `${publicUrl}/api/files/${record.collectionId}/${record.id}/${record.file}`;
|
||||||
return json({ record, url });
|
return json({ record, url });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ services:
|
||||||
image: spectado/pocketbase:latest
|
image: spectado/pocketbase:latest
|
||||||
container_name: massage-pocketbase
|
container_name: massage-pocketbase
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
# Internal only — accessed via the caddy reverse proxy
|
||||||
- "8090:80"
|
expose:
|
||||||
|
- "80"
|
||||||
volumes:
|
volumes:
|
||||||
- pocketbase:/pb/pb_data
|
- pocketbase:/pb/pb_data
|
||||||
|
|
||||||
|
|
@ -18,11 +19,24 @@ services:
|
||||||
- pocketbase
|
- pocketbase
|
||||||
environment:
|
environment:
|
||||||
POCKETBASE_INTERNAL_URL: http://pocketbase:80
|
POCKETBASE_INTERNAL_URL: http://pocketbase:80
|
||||||
PUBLIC_POCKETBASE_URL: http://localhost:8090
|
PUBLIC_POCKETBASE_URL: http://localhost:8080
|
||||||
ORIGIN: http://localhost:3000
|
ORIGIN: http://localhost:8080
|
||||||
BODY_SIZE_LIMIT: 5242880 # 5MB
|
BODY_SIZE_LIMIT: 5242880 # 5MB
|
||||||
|
# Internal only — served via the caddy reverse proxy
|
||||||
|
expose:
|
||||||
|
- "3000"
|
||||||
|
|
||||||
|
caddy:
|
||||||
|
image: caddy:2-alpine
|
||||||
|
container_name: massage-caddy
|
||||||
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "8080:8080"
|
||||||
|
volumes:
|
||||||
|
- ./Caddyfile:/etc/caddy/Caddyfile:ro
|
||||||
|
depends_on:
|
||||||
|
- app
|
||||||
|
- pocketbase
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
pocketbase:
|
pocketbase:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue