substr/main.ts

37 lines
1.0 KiB
TypeScript

import { Application, Router } from "@oak/oak";
import { log } from "./log.ts";
import naddrHandler from "./handlers/naddr.ts";
import nprofileHandler from "./handlers/nprofile.ts";
import npubHandler from "./handlers/npub.ts";
import usernameHandler from "./handlers/username.ts";
const router = new Router();
router.get("/:path", async (ctx: ctx) => {
const { path } = ctx.params;
if (path.startsWith("naddr")) {
await naddrHandler(ctx);
} else if (path.startsWith("nprofile")) {
await nprofileHandler(ctx);
} else if (path.startsWith("npub")) {
await npubHandler(ctx);
} else if (path.startsWith("@") || path.startsWith("~")) {
await usernameHandler(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}`)