import type { Server } from "bun"; import { parseArgs } from "util"; import { api } from "./api"; // PORT AND SSL STUFF const { values } = parseArgs({args: Bun.argv, allowPositionals: true, options: {dev: {type: "boolean"}}}); const dev = values.dev ?? false; console.log("Are we in development mode?", dev); const cert = Bun.file(process.env["SSL_CERT"] ?? "./cert.pem"); const key = Bun.file(process.env["SSL_KEY"] ?? "./key.pem"); const ssl_available = await cert.exists() && await key.exists(); console.log("Are we able to use SSL?", ssl_available); // const port = dev ? 8000 : ssl_available ? 443 : 80; const tls = ssl_available ? {cert, key} : undefined; const ports: number[] = [dev ? 8000 : 80]; if (!dev && tls) ports.push(443); console.log("Therefore, we are opening ports on:", ports); // ACTUAL CODE const servers: Server[] = ports.map((port) => Bun.serve({ idleTimeout: 30, tls: port !== 80 ? tls : undefined, port, fetch: async (req) => { try { const request_url = req.url.startsWith("/") ? "https://taevas.xyz".concat(req.url) : req.url; const url = new URL(request_url); const parameters = url.searchParams; // merciless sanitization let pathname = url.pathname; pathname = pathname .replace(/([^A-Za-z0-9/._-])/g, "") .replace(/(? console.log(`Listening on ${server.hostname}:${server.port}`)); console.log("\n\n--------\n\n");