From b3903c3ac6108eaa48e63cdaf58c9d1444a139e2 Mon Sep 17 00:00:00 2001 From: Samuel Shuert Date: Tue, 20 Jan 2026 19:05:59 +0000 Subject: [PATCH] feat: add gateway.ts --- server/books.ts | 2 +- server/gateway.ts | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 server/gateway.ts diff --git a/server/books.ts b/server/books.ts index 3984f7d..1c0ca0e 100644 --- a/server/books.ts +++ b/server/books.ts @@ -368,7 +368,7 @@ router.post("/", auth, async (req, res) => { }); router.get("/find", async (req, res) => { - res.locals.query = req.params as Partial; + res.locals.query = req.query as Partial; const books = filterBooks(res.locals.query); res.json(books); }); diff --git a/server/gateway.ts b/server/gateway.ts new file mode 100644 index 0000000..103a27f --- /dev/null +++ b/server/gateway.ts @@ -0,0 +1,25 @@ +import express from "express"; + +const app = express(); + +app.get("/books/:id", async (req, res) => { + const { id } = req.params; + const book = await fetch(`localhost:5713/books/${id}`); + const body = await book.json(); + res.send(body); +}); + +app.get("/tasks/:id", async (req, res) => { + const { id } = req.params; + const task = await fetch(`localhost:5713/tasks/${id}`); + const body = await task.json(); + res.send(body); +}); + +app.all("/*splat", (req, res) => { + res.status(404).send("Not Found"); +}); + +app.listen(3000, () => { + console.log("Server started on port 3000"); +}); -- 2.51.2