Compare commits
2 commits
be421d83cb
...
868be4bdda
| Author | SHA1 | Date | |
|---|---|---|---|
| 868be4bdda | |||
| 7107846624 |
6 changed files with 26 additions and 1 deletions
|
|
@ -3,6 +3,9 @@ SESSION_SECRET=change-me-to-a-long-random-string
|
||||||
ADMIN_USERNAME=admin
|
ADMIN_USERNAME=admin
|
||||||
ADMIN_PASSWORD=change-me
|
ADMIN_PASSWORD=change-me
|
||||||
SECURE_COOKIES=false
|
SECURE_COOKIES=false
|
||||||
|
# Behind a reverse proxy that terminates HTTPS (e.g. Nginx Proxy Manager): set both
|
||||||
|
# SECURE_COOKIES=true and TRUST_PROXY=1 (or the proxy's IP/subnet).
|
||||||
|
TRUST_PROXY=false
|
||||||
|
|
||||||
# Nextcloud connection
|
# Nextcloud connection
|
||||||
# Generate an app password in Nextcloud: Settings -> Security -> App passwords
|
# Generate an app password in Nextcloud: Settings -> Security -> App passwords
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,10 @@ docker compose up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
Reads secrets from `.env` in the project root (same variables as above).
|
Reads secrets from `.env` in the project root (same variables as above).
|
||||||
|
|
||||||
|
### Behind Nginx Proxy Manager (HTTPS)
|
||||||
|
|
||||||
|
HTTPS is required for the camera scan and the PWA install. Let the proxy terminate TLS and forward to the container over plain HTTP:
|
||||||
|
|
||||||
|
1. In `.env`, set `SECURE_COOKIES=true` and `TRUST_PROXY=1`. Without `TRUST_PROXY` the server thinks requests are plain HTTP and won't set the secure session cookie, so login doesn't stick.
|
||||||
|
2. In Nginx Proxy Manager, add a proxy host: scheme `http`, forward to the container's host/IP and `HOST_PORT` (or `notes:3000` if NPM shares a Docker network with it), request an SSL certificate, and enable *Force SSL*.
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ let workerPromise: Promise<import("tesseract.js").Worker> | null = null;
|
||||||
|
|
||||||
function getWorker() {
|
function getWorker() {
|
||||||
if (!workerPromise) {
|
if (!workerPromise) {
|
||||||
workerPromise = import("tesseract.js").then(({ createWorker }) => createWorker("eng"));
|
// "deu" is needed for umlauts and ß; the English model can't produce them.
|
||||||
|
workerPromise = import("tesseract.js").then(({ createWorker }) => createWorker("deu+eng"));
|
||||||
}
|
}
|
||||||
return workerPromise;
|
return workerPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanUpText(raw: string): string {
|
function cleanUpText(raw: string): string {
|
||||||
return raw
|
return raw
|
||||||
|
.normalize("NFC")
|
||||||
.replace(/[ \t]+\n/g, "\n")
|
.replace(/[ \t]+\n/g, "\n")
|
||||||
.replace(/\n{3,}/g, "\n\n")
|
.replace(/\n{3,}/g, "\n\n")
|
||||||
.trim();
|
.trim();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ services:
|
||||||
ADMIN_USERNAME: ${ADMIN_USERNAME}
|
ADMIN_USERNAME: ${ADMIN_USERNAME}
|
||||||
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
||||||
SECURE_COOKIES: ${SECURE_COOKIES:-false}
|
SECURE_COOKIES: ${SECURE_COOKIES:-false}
|
||||||
|
TRUST_PROXY: ${TRUST_PROXY:-false}
|
||||||
NEXTCLOUD_URL: ${NEXTCLOUD_URL}
|
NEXTCLOUD_URL: ${NEXTCLOUD_URL}
|
||||||
NEXTCLOUD_USERNAME: ${NEXTCLOUD_USERNAME}
|
NEXTCLOUD_USERNAME: ${NEXTCLOUD_USERNAME}
|
||||||
NEXTCLOUD_APP_PASSWORD: ${NEXTCLOUD_APP_PASSWORD}
|
NEXTCLOUD_APP_PASSWORD: ${NEXTCLOUD_APP_PASSWORD}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,21 @@ function required(name: string): string {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Passed to Express's "trust proxy": "true"/"false", a hop count, or a list of addresses/subnets.
|
||||||
|
function parseTrustProxy(value: string | undefined): boolean | number | string {
|
||||||
|
if (!value || value === "false") return false;
|
||||||
|
if (value === "true") return true;
|
||||||
|
if (/^\d+$/.test(value)) return Number(value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
port: Number(process.env.PORT ?? 3000),
|
port: Number(process.env.PORT ?? 3000),
|
||||||
sessionSecret: required("SESSION_SECRET"),
|
sessionSecret: required("SESSION_SECRET"),
|
||||||
adminUsername: required("ADMIN_USERNAME"),
|
adminUsername: required("ADMIN_USERNAME"),
|
||||||
adminPassword: required("ADMIN_PASSWORD"),
|
adminPassword: required("ADMIN_PASSWORD"),
|
||||||
secureCookies: process.env.SECURE_COOKIES === "true",
|
secureCookies: process.env.SECURE_COOKIES === "true",
|
||||||
|
trustProxy: parseTrustProxy(process.env.TRUST_PROXY),
|
||||||
|
|
||||||
nextcloudUrl: required("NEXTCLOUD_URL").replace(/\/+$/, ""),
|
nextcloudUrl: required("NEXTCLOUD_URL").replace(/\/+$/, ""),
|
||||||
nextcloudUsername: required("NEXTCLOUD_USERNAME"),
|
nextcloudUsername: required("NEXTCLOUD_USERNAME"),
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ import { notesRoutes } from "./routes/notes.js";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
// Behind a TLS-terminating reverse proxy, trust its X-Forwarded-* headers so secure cookies get set.
|
||||||
|
app.set("trust proxy", config.trustProxy);
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(sessionMiddleware);
|
app.use(sessionMiddleware);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue