diff --git a/.env.example b/.env.example index 91c4dfe..ecc5194 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,12 @@ -PUBLIC_POCKETBASE_URL=http://localhost:8090 -POCKETBASE_INTERNAL_URL=http://localhost:8090 +# Secrets read by docker-compose.yml via ${VAR:-} substitution. +# 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 diff --git a/AGENTS.md b/AGENTS.md index 5347ea2..40f7570 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,30 +77,22 @@ To add a new block type: add to `BlockType` union in `types.ts`, create renderer ## Build & Dev Commands ```sh -# Development (from app/) -cd app -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) +# Full stack (single entry point on port 8080) — the only supported way to run/develop +# Source changes require rebuilding; the container runs `node build`, not a dev server. docker compose up --build # App + PocketBase via Caddy: http://localhost:8080 # PocketBase admin: http://localhost:8080/_/ -# PocketBase only (for local dev outside Docker) -docker compose up pocketbase -# Direct access: http://localhost:8090/_/ +# Type checking (can run on the host with node_modules present, or inside the container) +cd app && npm run check + +# Production build only (run by the Dockerfile) +cd app && npm run build ``` ## Environment -- `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`) -- `ORIGIN` — SvelteKit origin for SSR (`http://localhost:8080`) -- Copy `app/.env.example` → `app/.env` for local dev +- `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`). Set directly in `docker-compose.yml`. +- `ORIGIN` — SvelteKit origin for SSR (`http://localhost:8080`). Set directly in `docker-compose.yml`. +- Stripe + PocketBase admin secrets are read from a root-level `.env` next to `docker-compose.yml`; see `.env.example`. diff --git a/README.md b/README.md index d87e180..5d3b8ca 100644 --- a/README.md +++ b/README.md @@ -9,26 +9,21 @@ A full-stack SvelteKit CMS for a single-operator massage studio. PocketBase prov - Tailwind CSS v4 + DaisyUI - 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. -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`. +The project runs exclusively through Docker Compose. There is no bare host dev mode. -> **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 @@ -51,7 +46,6 @@ Subsequent builds reuse the npm cache declared in the `Dockerfile`. - 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: @@ -60,7 +54,7 @@ The app container uses two PocketBase URLs: ## 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. 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: @@ -123,7 +117,7 @@ The shop/checkout blocks implement a basket-based booking flow: visitors add ser 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. 3. For local webhook testing, forward Stripe events with the CLI: ```sh diff --git a/app/.env.example b/app/.env.example deleted file mode 100644 index 71a3dce..0000000 --- a/app/.env.example +++ /dev/null @@ -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 diff --git a/app/README.md b/app/README.md deleted file mode 100644 index 993b3c4..0000000 --- a/app/README.md +++ /dev/null @@ -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. diff --git a/app/package-lock.json b/app/package-lock.json index 7f0587a..ca88bf6 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -26,7 +26,6 @@ "uuid": "^14.0.0" }, "devDependencies": { - "@sveltejs/adapter-auto": "^7.0.1", "@sveltejs/kit": "^2.57.0", "@sveltejs/vite-plugin-svelte": "^7.0.0", "@types/node": "^25.8.0", @@ -916,16 +915,6 @@ "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": { "version": "5.5.4", "resolved": "https://registry.npmjs.org/@sveltejs/adapter-node/-/adapter-node-5.5.4.tgz", diff --git a/app/package.json b/app/package.json index d181312..70f77eb 100644 --- a/app/package.json +++ b/app/package.json @@ -4,15 +4,12 @@ "version": "0.0.1", "type": "module", "scripts": { - "dev": "vite dev", "build": "vite build", - "preview": "vite preview", "prepare": "svelte-kit sync || echo ''", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" }, "devDependencies": { - "@sveltejs/adapter-auto": "^7.0.1", "@sveltejs/kit": "^2.57.0", "@sveltejs/vite-plugin-svelte": "^7.0.0", "@types/node": "^25.8.0", diff --git a/app/src/hooks.server.ts b/app/src/hooks.server.ts index 10588a6..89153e2 100644 --- a/app/src/hooks.server.ts +++ b/app/src/hooks.server.ts @@ -5,7 +5,7 @@ import { createPocketBase } from '$lib/pb'; export const handle: Handle = async ({ event, resolve }) => { event.locals.pb = createPocketBase( 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; diff --git a/app/src/lib/pb.ts b/app/src/lib/pb.ts index 3979d69..986d16a 100644 --- a/app/src/lib/pb.ts +++ b/app/src/lib/pb.ts @@ -2,7 +2,7 @@ import PocketBase from 'pocketbase'; import { env } from '$env/dynamic/public'; 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) { const pb = new PocketBase(url); diff --git a/app/src/lib/server/pb-admin.ts b/app/src/lib/server/pb-admin.ts index fa6646b..e8e6713 100644 --- a/app/src/lib/server/pb-admin.ts +++ b/app/src/lib/server/pb-admin.ts @@ -5,7 +5,7 @@ let adminPb: PocketBase | null = null; let authPromise: Promise | null = null; async function authenticate(): Promise { - const url = env.POCKETBASE_INTERNAL_URL || env.PUBLIC_POCKETBASE_URL || 'http://localhost:8080'; + const url = env.POCKETBASE_INTERNAL_URL; const pb = new PocketBase(url); pb.autoCancellation(false); diff --git a/app/src/routes/admin/api/export/+server.ts b/app/src/routes/admin/api/export/+server.ts index af8722a..d840e33 100644 --- a/app/src/routes/admin/api/export/+server.ts +++ b/app/src/routes/admin/api/export/+server.ts @@ -27,11 +27,10 @@ export const GET: RequestHandler = async ({ locals }) => { for (const url of extractImageUrls(g)) allUrls.add(url); } - // Fetch each image as base64 - // Inside Docker, stored PUBLIC_POCKETBASE_URL (http://localhost:8080) doesn't resolve - // from the app container, so we translate to the internal URL for fetching. - const publicBase = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8080'; - const internalBase = env.POCKETBASE_INTERNAL_URL || publicBase; + // Fetch each image as base64. Stored image URLs are public (http://localhost:8080) + // but the app container must fetch them via the internal Docker network URL. + const publicBase = env.PUBLIC_POCKETBASE_URL!; + const internalBase = env.POCKETBASE_INTERNAL_URL!; const images: Record = {}; for (const url of allUrls) { diff --git a/app/src/routes/admin/api/import/+server.ts b/app/src/routes/admin/api/import/+server.ts index db74b9a..4dde364 100644 --- a/app/src/routes/admin/api/import/+server.ts +++ b/app/src/routes/admin/api/import/+server.ts @@ -37,7 +37,7 @@ export const POST: RequestHandler = async ({ request, locals }) => { formData.append('alt', filename.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' ')); 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}`; keyToUrl.set(key, newUrl); diff --git a/app/src/routes/admin/api/upload/+server.ts b/app/src/routes/admin/api/upload/+server.ts index 755958b..2009082 100644 --- a/app/src/routes/admin/api/upload/+server.ts +++ b/app/src/routes/admin/api/upload/+server.ts @@ -17,7 +17,7 @@ export const POST: RequestHandler = async ({ request, locals }) => { try { 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}`; return json({ record, url }); } catch (e) {