Skip to content

Commit 648aad6

Browse files
committed
call to api8:
1 parent 26aec92 commit 648aad6

File tree

1 file changed

+4
-33
lines changed

1 file changed

+4
-33
lines changed

index.js

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,10 @@ const {
99
default: Axios
1010
} = require('axios');
1111

12-
app.get('/', async (req, res) => {
13-
try {
14-
const url = "https://api2.ip8.com/ip/info";
15-
const response = await Axios.post(url);
16-
if (response.status === 200 && response.data && response.data.ip && response.data.ip.length > 0) {
17-
const ipAddress = response.data.ip[0];
18-
if (response.data.data && response.data.data[ipAddress]) {
19-
const ipData = response.data.data[ipAddress];
20-
const data = {
21-
headers: req.headers['user-agent'],
22-
ip: ipAddress,
23-
isp: ipData.isp.isp,
24-
ispFull: ipData.isp.organization,
25-
city: ipData.geoip.city,
26-
pin: ipData.geoip.postalcode,
27-
timezone: ipData.geoip.timezone,
28-
country: ipData.geoip.country,
29-
continent: ipData.geoip.continent,
30-
latitude: ipData.geoip.latitude,
31-
longitude: ipData.geoip.longitude,
32-
};
33-
return res.status(200).json(data);
34-
} else {
35-
throw new Error("Invalid response data format");
36-
}
37-
} else {
38-
throw new Error("Invalid response from IP info API");
39-
}
40-
} catch (error) {
41-
console.error("Error fetching IP information:", error);
42-
return res.status(500).json({ error: "Internal Server Error" });
43-
}
44-
});
12+
app.get("/headers", async (req, res) => {
13+
const headers = req.headers;
14+
return res.json({data: headers['user-agent']})
15+
})
4516

4617
app.get('/weather/:city', async (req, res) => { // Because URL PARAMS ARE COOLER
4718
const city = req.params.city;

0 commit comments

Comments
 (0)