Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/routes/norad.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { Elysia } from "elysia";

import limiter from "../utils/ratelimiter";
import tleGetter from "../utils/tleGetter";

const noradRoute = new Elysia({ prefix: "/norad" }).get("/:id", async ({ params }) => {
const noradId = parseInt(params.id, 10);
const tleData = await tleGetter(noradId);
return new Response(tleData, { headers: { "Content-Type": "text/plain", "Cache-Control": "max-age=3600" } });
});
const noradRoute = new Elysia({ prefix: "/norad" })
.use(limiter)
.get("/:id", async ({ params }) => {
const noradId = parseInt(params.id, 10);

if (isNaN(noradId) || noradId < 1 || noradId > 999999) {
return new Response("Invalid NORAD ID. Must be a positive integer between 1 and 999999.", {
status: 400,
headers: { "Content-Type": "text/plain" },
});
}

const tleData = await tleGetter(noradId);
return new Response(tleData, { headers: { "Content-Type": "text/plain", "Cache-Control": "max-age=3600" } });
});

export default noradRoute;