Skip to content

Commit

Permalink
log IP address, add engines section, rename a function
Browse files Browse the repository at this point in the history
  • Loading branch information
canbax committed Aug 1, 2023
1 parent 1df9b19 commit 0d7aa6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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() });
}
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
}

1 comment on commit 0d7aa6e

@vercel
Copy link

@vercel vercel bot commented on 0d7aa6e Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

namaz-vakti-api – ./

namaz-vakti-api-canbax.vercel.app
namaz-vakti-api-git-main-canbax.vercel.app
namaz-vakti.vercel.app

Please sign in to comment.