#!/usr/bin/env node import { readFileSync } from "node:fs"; import { effectivePiWebConfig, maxUploadBytes } from "../config.js"; import { buildApp } from "./app.js"; const { config } = effectivePiWebConfig(); const app = await buildApp({ bodyLimit: maxUploadBytes(process.env, config), ...tlsOptions(process.env), }); await app.listen({ port: config.port ?? 8504, host: config.host ?? "127.0.0.1" }); function tlsOptions(env: NodeJS.ProcessEnv): { https?: { key: Buffer; cert: Buffer } } { const keyPath = env["PI_WEB_TLS_KEY"]; const certPath = env["PI_WEB_TLS_CERT"]; if ((keyPath === undefined || keyPath === "") && (certPath === undefined || certPath === "")) return {}; if (keyPath === undefined || keyPath === "" || certPath === undefined || certPath === "") { throw new Error("Set both PI_WEB_TLS_KEY and PI_WEB_TLS_CERT to enable HTTPS."); } return { https: { key: readFileSync(keyPath), cert: readFileSync(certPath) } }; }