generated from Schmax/deno-react-template
Hacked some shit together with Github Copilot
This commit is contained in:
3078
server/api/data.json
3078
server/api/data.json
File diff suppressed because it is too large
Load Diff
@@ -7,23 +7,11 @@ import data from "./api/data.json" with { type: "json" };
|
||||
export const app = new Application();
|
||||
const router = new Router();
|
||||
|
||||
router.get("/api/dinosaurs", (context) => {
|
||||
context.response.body = data;
|
||||
router.get("/api/snapshots", (context) => {
|
||||
context.response.headers.set("Content-Type", "application/json");
|
||||
context.response.body = JSON.stringify(data);
|
||||
});
|
||||
|
||||
router.get("/api/dinosaurs/:dinosaur", (context) => {
|
||||
if (!context?.params?.dinosaur) {
|
||||
context.response.body = "No dinosaur name provided.";
|
||||
}
|
||||
|
||||
const dinosaur = data.find((item) =>
|
||||
item.name.toLowerCase() === context.params.dinosaur.toLowerCase()
|
||||
);
|
||||
|
||||
context.response.body = dinosaur ?? "No dinosaur found.";
|
||||
});
|
||||
|
||||
|
||||
app.use(oakCors());
|
||||
app.use(router.routes());
|
||||
app.use(router.allowedMethods());
|
||||
|
||||
Reference in New Issue
Block a user