main
Peace 2 weeks ago
parent 4a5092007f
commit b4a5d816c0
  1. 26
      catDataMocking/src/app.ts

@ -8,11 +8,35 @@ const port: number = 8000;
app.use(cors());
// 전체 적용
app.use((req, res, next) => {
console.log(req.rawHeaders[1]);
next();
});
// 특정 REST 엔드포인트 적용
app.get("/cats/blue", (req, res) => {
console.log("This is /cats/blue GET middleware");
});
app.get("/", (req: express.Request, res: express.Response) => {
console.log(req);
res.send({ cats: Cat });
});
app.get("/cats/blue", (req, res) => {
res.send({ blue: Cat[0] });
});
app.get("/cats/som", (req, res) => {
res.send({ som: Cat[1] });
});
// not found
app.use((req, res, next) => {
console.log(req.rawHeaders[1]);
console.log("This is 404 middleware");
res.send({ error: "404 not found error" });
});
app.listen(port, () => {
console.log(`server is on ${port}`);
});

Loading…
Cancel
Save