Repository Public
1import "./scripts/_env";2import { createServer } from "node:http";3import next from "next";4import { handleMedia } from "./src/server/media-http";56/**7 * Music SP web process: one Node HTTP server. Audio and cover requests are answered natively8 * (src/server/media-http.ts — exact Content-Length / Range framing); everything else goes to Next.js.9 */10const port = Number(process.env.PORT ?? 8690);11const hostname = process.env.HOST ?? "0.0.0.0";12const dev = process.env.NODE_ENV !== "production";1314async function main() {15 const app = next({ dev, hostname, port });16 await app.prepare();17 const handle = app.getRequestHandler();18 const server = createServer((req, res) => {19 handleMedia(req, res).then((done) => { if (!done) return handle(req, res); }).catch((e) => {20 console.error("[server]", e instanceof Error ? e.message : e);21 if (!res.headersSent) res.writeHead(500); res.end();22 });23 });24 // Uploads arrive in chunks of a few MB; a slow phone connection must not be cut mid-chunk.25 server.requestTimeout = 10 * 60_000; server.headersTimeout = 60_000; server.keepAliveTimeout = 65_000;26 server.listen(port, hostname, () => console.log(`[web] Music SP listening on http://${hostname}:${port} (${dev ? "development" : "production"})`));27 const stop = () => server.close(() => process.exit(0));28 process.on("SIGTERM", stop); process.on("SIGINT", stop);29}30main().catch((e) => { console.error(e); process.exit(1); });31