mirror of
https://github.com/traberph/short.git
synced 2026-11-22 22:55:12 +00:00
Replaces the Next.js/Prisma/next-auth app with a single-container Hono server, SQLite via Drizzle, OIDC login against Authentik and a React/Vite admin UI that talks to a JSON API. - users get /<username>/<code>, admins (Authentik group) get root codes, pinning and full access - link pages with link and Markdown text blocks, themes, avatars - editable 302 redirects, random or custom codes - personal API tokens, CSRF-protected cookie sessions - privacy-friendly stats: daily-rotating visitor salt, 90-day click retention with daily totals kept - QR codes as PNG/SVG - tests for permissions, auth, redirects and stats; CI runs them before publishing images See REQUIREMENTS.md for the full requirement list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import path from "node:path";
|
|
|
|
export interface Config {
|
|
baseUrl: string;
|
|
oidc: { issuer: string; clientId: string; clientSecret: string };
|
|
adminGroup: string;
|
|
sessionSecret: string;
|
|
dataDir: string;
|
|
timezone: string;
|
|
trustProxy: boolean;
|
|
logoDevToken: string | undefined;
|
|
disableAttribution: boolean;
|
|
retentionDays: number;
|
|
port: number;
|
|
}
|
|
|
|
function required(env: NodeJS.ProcessEnv, name: string): string {
|
|
const value = env[name];
|
|
if (!value) throw new Error(`Missing required environment variable ${name}`);
|
|
return value;
|
|
}
|
|
|
|
export function loadConfig(env: NodeJS.ProcessEnv = process.env): Config {
|
|
const timezone = env.TIMEZONE || "UTC";
|
|
// Throws a RangeError early for unknown timezones.
|
|
new Intl.DateTimeFormat("en-CA", { timeZone: timezone });
|
|
|
|
const sessionSecret = required(env, "SESSION_SECRET");
|
|
if (sessionSecret.length < 32) throw new Error("SESSION_SECRET must be at least 32 characters");
|
|
|
|
return {
|
|
baseUrl: required(env, "BASE_URL").replace(/\/+$/, ""),
|
|
oidc: {
|
|
issuer: required(env, "OIDC_ISSUER"),
|
|
clientId: required(env, "OIDC_CLIENT_ID"),
|
|
clientSecret: required(env, "OIDC_CLIENT_SECRET"),
|
|
},
|
|
adminGroup: env.ADMIN_GROUP || "short-admins",
|
|
sessionSecret,
|
|
dataDir: path.resolve(env.DATA_DIR || "./data"),
|
|
timezone,
|
|
trustProxy: env.TRUST_PROXY === "true",
|
|
logoDevToken: env.LOGO_DEV_TOKEN || undefined,
|
|
disableAttribution: env.DISABLE_ATTRIBUTION === "true",
|
|
retentionDays: 90,
|
|
port: Number(env.PORT || 3000),
|
|
};
|
|
}
|