CMU Coding Bootcamp

feat: add gateway.ts

thecoded.prof b3903c3a 6e6447bd

verified
+26 -1
+1 -1
server/books.ts
··· 368 }); 369 370 router.get("/find", async (req, res) => { 371 - res.locals.query = req.params as Partial<BooksQuery>; 372 const books = filterBooks(res.locals.query); 373 res.json(books); 374 });
··· 368 }); 369 370 router.get("/find", async (req, res) => { 371 + res.locals.query = req.query as Partial<BooksQuery>; 372 const books = filterBooks(res.locals.query); 373 res.json(books); 374 });
+25
server/gateway.ts
···
··· 1 + import express from "express"; 2 + 3 + const app = express(); 4 + 5 + app.get("/books/:id", async (req, res) => { 6 + const { id } = req.params; 7 + const book = await fetch(`localhost:5713/books/${id}`); 8 + const body = await book.json(); 9 + res.send(body); 10 + }); 11 + 12 + app.get("/tasks/:id", async (req, res) => { 13 + const { id } = req.params; 14 + const task = await fetch(`localhost:5713/tasks/${id}`); 15 + const body = await task.json(); 16 + res.send(body); 17 + }); 18 + 19 + app.all("/*splat", (req, res) => { 20 + res.status(404).send("Not Found"); 21 + }); 22 + 23 + app.listen(3000, () => { 24 + console.log("Server started on port 3000"); 25 + });