removed bare dev fallback routes, only support developmnet in

docker/podman
This commit is contained in:
Jakub Dorfman 2026-08-19 13:22:51 +02:00
parent 702d99b9ed
commit c7f6b30b87
13 changed files with 47 additions and 121 deletions

View file

@ -1,2 +1,12 @@
PUBLIC_POCKETBASE_URL=http://localhost:8090 # Secrets read by docker-compose.yml via ${VAR:-} substitution.
POCKETBASE_INTERNAL_URL=http://localhost:8090 # Copy to .env at the project root and fill in.
# Stripe
STRIPE_SECRET_KEY=sk_test_...
PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
STRIPE_CURRENCY=eur
# PocketBase superuser credentials (used by server-side basket/checkout/webhook APIs)
POCKETBASE_ADMIN_EMAIL=admin@example.com
POCKETBASE_ADMIN_PASSWORD=changeme

View file

@ -77,30 +77,22 @@ To add a new block type: add to `BlockType` union in `types.ts`, create renderer
## Build & Dev Commands ## Build & Dev Commands
```sh ```sh
# Development (from app/) # Full stack (single entry point on port 8080) — the only supported way to run/develop
cd app # Source changes require rebuilding; the container runs `node build`, not a dev server.
npm install
npm run dev # http://localhost:5173
# Production build
npm run build
# Type checking
npm run check
# Docker full stack (single entry point on port 8080)
docker compose up --build docker compose up --build
# App + PocketBase via Caddy: http://localhost:8080 # App + PocketBase via Caddy: http://localhost:8080
# PocketBase admin: http://localhost:8080/_/ # PocketBase admin: http://localhost:8080/_/
# PocketBase only (for local dev outside Docker) # Type checking (can run on the host with node_modules present, or inside the container)
docker compose up pocketbase cd app && npm run check
# Direct access: http://localhost:8090/_/
# Production build only (run by the Dockerfile)
cd app && npm run build
``` ```
## Environment ## Environment
- `PUBLIC_POCKETBASE_URL` — public-facing PocketBase URL, now accessed through the Caddy reverse proxy (default `http://localhost:8080`) - `PUBLIC_POCKETBASE_URL` — public-facing PocketBase URL, accessed through the Caddy reverse proxy (`http://localhost:8080`). Set directly in `docker-compose.yml`.
- `POCKETBASE_INTERNAL_URL` — internal Docker network URL (`http://pocketbase:80`) - `POCKETBASE_INTERNAL_URL` — internal Docker network URL (`http://pocketbase:80`). Set directly in `docker-compose.yml`.
- `ORIGIN` — SvelteKit origin for SSR (`http://localhost:8080`) - `ORIGIN` — SvelteKit origin for SSR (`http://localhost:8080`). Set directly in `docker-compose.yml`.
- Copy `app/.env.example` → `app/.env` for local dev - Stripe + PocketBase admin secrets are read from a root-level `.env` next to `docker-compose.yml`; see `.env.example`.

View file

@ -9,26 +9,21 @@ A full-stack SvelteKit CMS for a single-operator massage studio. PocketBase prov
- Tailwind CSS v4 + DaisyUI - Tailwind CSS v4 + DaisyUI
- Docker Compose with three services: `app`, `pocketbase`, and `caddy` (reverse proxy) - Docker Compose with three services: `app`, `pocketbase`, and `caddy` (reverse proxy)
## Local development ## Development
1. Install Node.js `22.x` or another version accepted by SvelteKit's Vite plugin. The project runs exclusively through Docker Compose. There is no bare host dev mode.
2. Copy the app env file:
```sh
cp app/.env.example app/.env
```
3. Start PocketBase on port `8090`. With Docker:
```sh
docker compose up pocketbase
```
4. In another terminal:
```sh
cd app
npm install
npm run dev
```
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`. 1. Copy the env file and fill in the secrets:
```sh
cp .env.example .env
```
2. Build and start the full stack:
```sh
docker compose up --build
```
3. Visit `http://localhost:8080`.
The single Caddy entry point on port `8080` fronts both the SvelteKit app and PocketBase. Source changes require rebuilding (`docker compose up --build`); the container runs the production build (`node build`), not a dev server.
## Docker Compose ## Docker Compose
@ -51,7 +46,6 @@ Subsequent builds reuse the npm cache declared in the `Dockerfile`.
- SvelteKit app: `http://localhost:8080/` (or any non-API path) - SvelteKit app: `http://localhost:8080/` (or any non-API path)
- PocketBase admin UI: `http://localhost:8080/_/` - PocketBase admin UI: `http://localhost:8080/_/`
- PocketBase REST API: `http://localhost:8080/api/` - 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:
@ -60,7 +54,7 @@ The app container uses two PocketBase URLs:
## PocketBase setup ## PocketBase setup
1. Open `http://localhost:8080/_/` (or `http://localhost:8090/_/` for direct access). 1. Open `http://localhost:8080/_/`.
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:
@ -123,7 +117,7 @@ The shop/checkout blocks implement a basket-based booking flow: visitors add ser
Setup: Setup:
1. Add the Stripe + PocketBase-admin vars from `app/.env.example` to `app/.env` (local dev) or a root-level `.env` next to `docker-compose.yml` (Docker). 1. Add the Stripe + PocketBase-admin vars from `.env.example` to `.env` at the project root.
2. `POCKETBASE_ADMIN_EMAIL` / `POCKETBASE_ADMIN_PASSWORD` are the credentials of the PocketBase superuser you created — the basket/checkout/webhook APIs use a server-side admin client so collection rules can stay admin-only. 2. `POCKETBASE_ADMIN_EMAIL` / `POCKETBASE_ADMIN_PASSWORD` are the credentials of the PocketBase superuser you created — the basket/checkout/webhook APIs use a server-side admin client so collection rules can stay admin-only.
3. For local webhook testing, forward Stripe events with the CLI: 3. For local webhook testing, forward Stripe events with the CLI:
```sh ```sh

View file

@ -1,13 +0,0 @@
PUBLIC_POCKETBASE_URL=http://localhost:8080
POCKETBASE_INTERNAL_URL=http://pocketbase:80
ORIGIN=http://localhost:8080
# Stripe
STRIPE_SECRET_KEY=sk_test_...
PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
STRIPE_CURRENCY=eur
# PocketBase admin credentials (for server-side basket/checkout/webhook APIs)
POCKETBASE_ADMIN_EMAIL=admin@example.com
POCKETBASE_ADMIN_PASSWORD=changeme

View file

@ -1,42 +0,0 @@
# sv
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```sh
# create a new project
npx sv create my-app
```
To recreate this project with the same configuration:
```sh
# recreate this project
npx sv@0.15.3 create --template minimal --types ts --install npm app
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```sh
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```sh
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.

11
app/package-lock.json generated
View file

@ -26,7 +26,6 @@
"uuid": "^14.0.0" "uuid": "^14.0.0"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-auto": "^7.0.1",
"@sveltejs/kit": "^2.57.0", "@sveltejs/kit": "^2.57.0",
"@sveltejs/vite-plugin-svelte": "^7.0.0", "@sveltejs/vite-plugin-svelte": "^7.0.0",
"@types/node": "^25.8.0", "@types/node": "^25.8.0",
@ -916,16 +915,6 @@
"acorn": "^8.9.0" "acorn": "^8.9.0"
} }
}, },
"node_modules/@sveltejs/adapter-auto": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-auto/-/adapter-auto-7.0.1.tgz",
"integrity": "sha512-dvuPm1E7M9NI/+canIQ6KKQDU2AkEefEZ2Dp7cY6uKoPq9Z/PhOXABe526UdW2mN986gjVkuSLkOYIBnS/M2LQ==",
"dev": true,
"license": "MIT",
"peerDependencies": {
"@sveltejs/kit": "^2.0.0"
}
},
"node_modules/@sveltejs/adapter-node": { "node_modules/@sveltejs/adapter-node": {
"version": "5.5.4", "version": "5.5.4",
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-node/-/adapter-node-5.5.4.tgz", "resolved": "https://registry.npmjs.org/@sveltejs/adapter-node/-/adapter-node-5.5.4.tgz",

View file

@ -4,15 +4,12 @@
"version": "0.0.1", "version": "0.0.1",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite dev",
"build": "vite build", "build": "vite build",
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''", "prepare": "svelte-kit sync || echo ''",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-auto": "^7.0.1",
"@sveltejs/kit": "^2.57.0", "@sveltejs/kit": "^2.57.0",
"@sveltejs/vite-plugin-svelte": "^7.0.0", "@sveltejs/vite-plugin-svelte": "^7.0.0",
"@types/node": "^25.8.0", "@types/node": "^25.8.0",

View file

@ -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:8080' env.POCKETBASE_INTERNAL_URL
); );
event.locals.user = event.locals.pb.authStore.record; event.locals.user = event.locals.pb.authStore.record;

View file

@ -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:8080'; export const pbUrl = env.PUBLIC_POCKETBASE_URL;
export function createPocketBase(authCookie?: string, url = pbUrl) { export function createPocketBase(authCookie?: string, url = pbUrl) {
const pb = new PocketBase(url); const pb = new PocketBase(url);

View file

@ -5,7 +5,7 @@ let adminPb: PocketBase | null = null;
let authPromise: Promise<PocketBase> | null = null; let authPromise: Promise<PocketBase> | null = null;
async function authenticate(): Promise<PocketBase> { async function authenticate(): Promise<PocketBase> {
const url = env.POCKETBASE_INTERNAL_URL || env.PUBLIC_POCKETBASE_URL || 'http://localhost:8080'; const url = env.POCKETBASE_INTERNAL_URL;
const pb = new PocketBase(url); const pb = new PocketBase(url);
pb.autoCancellation(false); pb.autoCancellation(false);

View file

@ -27,11 +27,10 @@ export const GET: RequestHandler = async ({ locals }) => {
for (const url of extractImageUrls(g)) allUrls.add(url); for (const url of extractImageUrls(g)) allUrls.add(url);
} }
// Fetch each image as base64 // Fetch each image as base64. Stored image URLs are public (http://localhost:8080)
// Inside Docker, stored PUBLIC_POCKETBASE_URL (http://localhost:8080) doesn't resolve // but the app container must fetch them via the internal Docker network URL.
// from the app container, so we translate to the internal URL for fetching. const publicBase = env.PUBLIC_POCKETBASE_URL!;
const publicBase = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8080'; const internalBase = env.POCKETBASE_INTERNAL_URL!;
const internalBase = env.POCKETBASE_INTERNAL_URL || publicBase;
const images: Record<string, string> = {}; const images: Record<string, string> = {};
for (const url of allUrls) { for (const url of allUrls) {

View file

@ -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:8080'; const publicUrl = env.PUBLIC_POCKETBASE_URL;
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);

View file

@ -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:8080'; const publicUrl = env.PUBLIC_POCKETBASE_URL;
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) {