upd
This commit is contained in:
@@ -5,6 +5,7 @@ import cors from "cors";
|
||||
import mailRoute from "./routes/mail";
|
||||
import projectRoute from "./routes/projects";
|
||||
import uploadRoute from "./routes/upload";
|
||||
import getRegionNameRoute from "./routes/getRegionName";
|
||||
|
||||
connectDB();
|
||||
|
||||
@@ -17,6 +18,7 @@ app.use(cors({ origin: "*" }));
|
||||
app.use("/mail", mailRoute);
|
||||
app.use("/projects", projectRoute);
|
||||
app.use("/upload", uploadRoute);
|
||||
app.use("/getRegionName", getRegionNameRoute);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is listening on port ${port}`);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Router } from "express";
|
||||
import fs from "fs";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/", async (req, res) => {
|
||||
const ip = req.headers["x-forwarded-for"];
|
||||
|
||||
try {
|
||||
const { countryCode, region, regionName }: any = await (
|
||||
await fetch(`http://ip-api.com/json/${ip}?lang=ru`)
|
||||
).json();
|
||||
|
||||
if (countryCode === "RU") {
|
||||
fs.appendFileSync(
|
||||
"./log.txt",
|
||||
`${countryCode}-${region} (${regionName})\n`
|
||||
);
|
||||
}
|
||||
|
||||
res.json({ regionName });
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
res.json({ error: error.message });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const getRegionNameRoute = router;
|
||||
|
||||
export default getRegionNameRoute;
|
||||
Reference in New Issue
Block a user