Changeset 09ee2bd in Klonkt
- Timestamp:
- 06/23/2026 09:25:42 PM (3 months ago)
- Branches:
- main
- Children:
- f99bbe8
- Parents:
- 45271b7
- Files:
-
- 4 edited
-
.env.example (modified) (1 diff)
-
README.md (modified) (2 diffs)
-
docker-compose.yml (modified) (1 diff)
-
src/server.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
.env.example
r45271b7 r09ee2bd 1 1 NODE_ENV=development 2 2 PORT=3000 3 SESSION_SECRET=change-me-to-a-strong-random-string-min-32-chars 3 # Secret used to sign login-session cookies. Leave EMPTY to auto-generate a strong 4 # one on first start (saved to storage/.session-secret, stays stable across 5 # restarts/updates). Or set your own: openssl rand -hex 32 6 SESSION_SECRET= 4 7 DATABASE_PATH=./storage/database.sqlite 5 8 MEDIA_PATH=./storage/media 6 9 7 # Canonical public URL of this site (scheme + host, no path/slash). Used for 8 # links in emails (password reset) instead of request headers — prevents 9 # host-header spoofing. Not set? Then it falls back to the request host (dev). 10 PUBLIC_BASE_URL=https://example.com 10 # Canonical public URL of this site (scheme + host, no trailing slash), e.g. 11 # https://yourdomain.com . Used to build correct links in emails (password reset) 12 # and OAuth redirects instead of trusting request headers (anti-spoofing). 13 # Optional: leave empty and it falls back to the request host (fine for local/dev); 14 # set it for production so email/login links point at the right place. 15 PUBLIC_BASE_URL= 11 16 12 17 # ── Administrator ─────────────────────────────────────────────────── -
README.md
r45271b7 r09ee2bd 58 58 git clone https://github.com/roboburr/klonkt.git 59 59 cd klonkt 60 cp .env.example .env # then edit .env: set SESSION_SECRET + PUBLIC_BASE_URL60 cp .env.example .env # works as-is; optionally set PUBLIC_BASE_URL to your domain 61 61 docker compose up -d 62 62 ``` 63 63 64 `SESSION_SECRET` is auto-generated on first start, so the defaults work as-is. 64 65 Klonkt runs on port 3000 — put your own reverse proxy in front for HTTPS (see 65 66 step 5 of Option C). Data (database + media) stays in the `klonkt-data` volume, … … 79 80 ``` 80 81 81 **2. Create your config** — copy the example and edit it; at minimum set a long 82 random `SESSION_SECRET` and your `PUBLIC_BASE_URL` (e.g. `https://yourdomain.com`): 82 **2. Create your config.** `SESSION_SECRET` (the key that signs login cookies) is 83 auto-generated on first start, so this works as-is. For production, set 84 `PUBLIC_BASE_URL` to your site address (e.g. `https://yourdomain.com`) so email & 85 login links are correct: 83 86 84 87 ```bash 85 88 cp .env.example .env 86 nano .env 89 nano .env # optional: PUBLIC_BASE_URL, plus SMTP / Google if you want them 87 90 ``` 88 91 -
docker-compose.yml
r45271b7 r09ee2bd 1 # Klonkt — zelf-host metDocker Compose.1 # Klonkt — self-host with Docker Compose. 2 2 # 3 # 1. cp .env.example .env en vul SESSION_SECRET + PUBLIC_BASE_URL in 3 # 1. cp .env.example .env (works as-is: SESSION_SECRET is auto-generated; 4 # optionally set PUBLIC_BASE_URL to your domain so 5 # email/login links are correct) 4 6 # 2. docker compose up -d 5 # 3. open je site en maak via /auth/register je beheerdersaccount aan7 # 3. open your site and create your admin account at /auth/register 6 8 # 7 # Standaard luistert de app op poort 3000. Zet er een reverse-proxy (Caddy/8 # nginx) vóór voor HTTPS op je domein — zie README.9 # The app listens on port 3000. Put a reverse proxy (Caddy/nginx) in front for 10 # HTTPS on your domain — see README. 9 11 services: 10 12 klonkt: -
src/server.js
r45271b7 r09ee2bd 13 13 import path from 'path'; 14 14 import fs from 'fs'; 15 import crypto from 'crypto'; 15 16 import { fileURLToPath } from 'url'; 16 17 import http from 'http'; … … 63 64 import changelogRoutes from './routes/changelog.js'; 64 65 66 // SESSION_SECRET: use the env var if set. Otherwise auto-generate a strong one 67 // and persist it next to the database, so it stays stable across restarts and 68 // updates. This lets Docker / bare-Node installs run with zero manual config. 65 69 if (!process.env.SESSION_SECRET) { 66 console.error('❌ FATAL: SESSION_SECRET is required'); 67 process.exit(1); 70 const dataDir = path.dirname(process.env.DATABASE_PATH || './storage/database.sqlite'); 71 const secretFile = path.join(dataDir, '.session-secret'); 72 try { process.env.SESSION_SECRET = fs.readFileSync(secretFile, 'utf8').trim(); } catch { /* not yet generated */ } 73 if (!process.env.SESSION_SECRET) { 74 fs.mkdirSync(dataDir, { recursive: true }); 75 process.env.SESSION_SECRET = crypto.randomBytes(32).toString('hex'); 76 fs.writeFileSync(secretFile, process.env.SESSION_SECRET, { mode: 0o600 }); 77 console.log(`🔑 Generated a SESSION_SECRET (stored in ${secretFile})`); 78 } 68 79 } 69 80 81 // A SESSION_SECRET that was explicitly set in the env must still be strong in prod. 70 82 if (process.env.NODE_ENV === 'production' && process.env.SESSION_SECRET.length < 32) { 71 console.error('❌ FATAL: SESSION_SECRET too weak for production');83 console.error('❌ FATAL: SESSION_SECRET is too weak for production (set a longer, random one in .env)'); 72 84 process.exit(1); 73 85 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)