- Replace hand-written node:sqlite queries with a Prisma client using the better-sqlite3 driver adapter - Version the schema with migrations: baseline table, timestamp normalisation, and WAL journal mode - Store timestamps with an explicit UTC offset so they stop being parsed as local time - Show created/updated times on the edit page, formatted with dayjs - Move the root redirect into next.config to avoid a prerender error - Run migrations from the container entrypoint before starting the server BREAKING CHANGE: DNSMASQ_ADMIN_DB_PATH is replaced by DATABASE_URL, which must be a Prisma connection URL (file:./data/dnsmasq-admin.db). Existing database files are migrated in place and need no conversion.
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import path from "node:path"
|
|
|
|
function withDefault(name: string, fallback: string): string {
|
|
const raw = process.env[name]
|
|
return raw && raw.trim() ? raw.trim() : fallback
|
|
}
|
|
|
|
function toAbsolute(target: string): string {
|
|
return path.isAbsolute(target) ? target : path.resolve(process.cwd(), target)
|
|
}
|
|
|
|
/**
|
|
* Runtime configuration. Everything is optional with sensible defaults so the app can
|
|
* boot locally without any env file; see `.env.example` for the deploy-time values.
|
|
*/
|
|
export const env = {
|
|
/**
|
|
* Prisma connection URL for the SQLite database — the single source of truth for records.
|
|
*
|
|
* Left as-is rather than resolved with `toAbsolute()`, because Prisma and better-sqlite3
|
|
* resolve relative paths against the working directory, which is what `./data/...` in
|
|
* `.env` already assumes.
|
|
*/
|
|
databaseUrl: withDefault("DATABASE_URL", "file:./data/dnsmasq-admin.db"),
|
|
/** Managed dnsmasq config file that this app regenerates on every apply. */
|
|
confPath: toAbsolute(withDefault("DNSMASQ_ADMIN_CONF_PATH", "./data/dnsmasq-admin.conf")),
|
|
/** Container that gets restarted through the Docker socket after an apply. */
|
|
containerName: withDefault("DNSMASQ_CONTAINER_NAME", "dnsmasq"),
|
|
dockerSocket: withDefault("DNSMASQ_ADMIN_DOCKER_SOCKET", "/var/run/docker.sock"),
|
|
/** DNS server that the /resolve page queries. */
|
|
dnsServer: withDefault("DNSMASQ_SERVER_IP", "127.0.0.1"),
|
|
}
|