substr/main.ts
2024-10-20 21:10:58 +02:00

31 lines
817 B
TypeScript

import { Application, Router } from "@oak/oak";
import { log } from "./log.ts";
import naddrHandler from "./handlers/naddr.ts";
import nprofileHandler from "./handlers/nprofile.ts";
const router = new Router();
router.get("/:path", async (ctx: ctx) => {
const { path } = ctx.params;
if (path && path.startsWith("naddr")) {
await naddrHandler(ctx);
} else if (prefix && prefix.startsWith("nprofile")) {
await nprofileHandler(ctx);
} else {
ctx.response.status = 404;
ctx.response.body = "Not Found";
}
log(`${ctx.request.method} ${ctx.request.url} - ${ctx.response.status}`, "gray");
});
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
const PORT = 8000;
app.listen({ port: PORT });
console.log(`App listening on http://localhost:${PORT}`)