diff --git a/api/index.ts b/api/index.ts index a68fa93..2ef584d 100644 --- a/api/index.ts +++ b/api/index.ts @@ -12,10 +12,10 @@ import { readFileSync, writeFile } from "fs"; export const app: Express = express(); -/** use this function like `app.use(allowOrigion4All);` for an express app - * Make API accessiable for all clients. Not for only clients from a specific domain. +/** use this function like `app.use(allowOriginForAll);` for an express app + * Make API accessible for all clients. Not for only clients from a specific domain. */ -const allowOrigin4All: RequestHandler = ( +const allowOriginForAll: RequestHandler = ( _: Request, res: Response, next: NextFunction @@ -34,8 +34,9 @@ let totalVisits = readTotalVisitCount(); export const writerTimerID = setInterval(writeTotalVisitCount, 3000); -app.use(allowOrigin4All); +app.use(allowOriginForAll); app.use(express.static("public")); +app.use(logIPAdress); app.get("/api/timesFromCoordinates", getTimesFromCoordinates); app.get("/api/timesFromPlace", getTimesFromPlace); @@ -161,6 +162,10 @@ function getIPAdress(req: Request, res: Response) { res.send({ IP: req.headers["x-forwarded-for"] }); } +function logIPAdress(req: Request) { + console.log("IP address:", req.headers["x-forwarded-for"]); +} + function getTotalVisitCount(_: Request, res: Response) { res.send({ totalVisitCount: readTotalVisitCount() }); } diff --git a/package.json b/package.json index 0b5de3d..a976585 100644 --- a/package.json +++ b/package.json @@ -44,10 +44,14 @@ "ts-node": "^10.9.1", "typescript": "^4.9.3" }, + "engines": { + "node": ">=18.15.0", + "npm": ">=9.5.0" + }, "lint-staged": { "*.{ts,js}": [ "prettier --write", "eslint --max-warnings=0" ] } -} +} \ No newline at end of file