/** * Local HTTPS development server. * * Creates an HTTPS proxy in front of Next.js dev server so that * the EVE SSO callback URL (https://localhost:3000/...) works locally. * * Usage: node scripts/dev-https.js * (or: npm run dev:https) * * Prerequisites: * 1. Run ./scripts/generate-cert.sh to create certs/ * 2. Trust the self-signed cert in your OS/browser */ const { createServer } = require("https"); const { parse } = require("url"); const next = require("next"); const fs = require("fs"); const path = require("path"); const dev = process.env.NODE_ENV !== "production"; const hostname = "localhost"; const port = parseInt(process.env.PORT || "3000", 10); const certDir = path.join(__dirname, "..", "certs"); const keyPath = path.join(certDir, "localhost-key.pem"); const certPath = path.join(certDir, "localhost.pem"); if (!fs.existsSync(keyPath) || !fs.existsSync(certPath)) { console.error( "Self-signed certificates not found.\n" + "Run: ./scripts/generate-cert.sh\n" + "Then try again." ); process.exit(1); } const httpsOptions = { key: fs.readFileSync(keyPath), cert: fs.readFileSync(certPath), }; const app = next({ dev, hostname, port }); const handle = app.getRequestHandler(); app.prepare().then(() => { createServer(httpsOptions, async (req, res) => { try { const parsedUrl = parse(req.url, true); await handle(req, res, parsedUrl); } catch (err) { console.error("Error handling request:", err); res.statusCode = 500; res.end("Internal Server Error"); } }).listen(port, () => { console.log(`\n ▶ HTTPS server running at https://${hostname}:${port}\n`); console.log(` EVE SSO Login: https://${hostname}:${port}/api/auth/eve-sso`); console.log(` EVE SSO Callback: https://${hostname}:${port}/api/auth/callback/eve-sso`); console.log(` Sync trigger: POST https://${hostname}:${port}/api/eve/sync`); console.log(` Sync status: GET https://${hostname}:${port}/api/eve/sync\n`); }); });