Skip to content

Commit

Permalink
log ip of request
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed Mar 12, 2024
1 parent a3725fa commit 2b3236a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ app.use(compression());
app.use(helmet());
app.use(cors());

app.get("/v1/products", (_req, res) => {
app.get("/v1/products", (req, res) => {
// print who IP of the request
const ip = req.headers["x-forwarded-for"] || req.socket.remoteAddress;
console.log(`Request from ${ip}`);
res.sendFile(`${__dirname}/data/products.json`);
});

Expand Down

0 comments on commit 2b3236a

Please sign in to comment.