46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
/**
|
|
* Choices standalone server — independent deployment at choices.jeffemmett.com.
|
|
*/
|
|
|
|
import { Hono } from "hono";
|
|
import { resolve } from "node:path";
|
|
import { choicesModule } from "./mod";
|
|
|
|
const PORT = Number(process.env.PORT) || 3000;
|
|
const DIST_DIR = resolve(import.meta.dir, "../../dist");
|
|
|
|
const app = new Hono();
|
|
|
|
app.get("/.well-known/webauthn", (c) => {
|
|
return c.json(
|
|
{ origins: ["https://rspace.online"] },
|
|
200,
|
|
{ "Access-Control-Allow-Origin": "*", "Cache-Control": "public, max-age=3600" }
|
|
);
|
|
});
|
|
|
|
app.route("/", choicesModule.routes);
|
|
|
|
Bun.serve({
|
|
port: PORT,
|
|
async fetch(req) {
|
|
const url = new URL(req.url);
|
|
if (url.pathname !== "/" && !url.pathname.startsWith("/api/")) {
|
|
const assetPath = url.pathname.slice(1);
|
|
if (assetPath.includes(".")) {
|
|
const file = Bun.file(resolve(DIST_DIR, assetPath));
|
|
if (await file.exists()) {
|
|
const ct = assetPath.endsWith(".js") ? "application/javascript" :
|
|
assetPath.endsWith(".css") ? "text/css" :
|
|
assetPath.endsWith(".html") ? "text/html" :
|
|
"application/octet-stream";
|
|
return new Response(file, { headers: { "Content-Type": ct } });
|
|
}
|
|
}
|
|
}
|
|
return app.fetch(req);
|
|
},
|
|
});
|
|
|
|
console.log(`rChoices standalone server running on http://localhost:${PORT}`);
|