fixup
This commit is contained in:
+2
-2
@@ -6,8 +6,8 @@ NEXT_PUBLIC_APP_URL=http://localhost:3000
|
||||
# -----------------------------------------------------------------------------
|
||||
# Authentication (NextAuth.js 5.0.x)
|
||||
# -----------------------------------------------------------------------------
|
||||
AUTH_SECRET=
|
||||
AUTH_URL=http://localhost:3000/api/auth
|
||||
AUTH_SECRET=abc123
|
||||
AUTH_URL=http://localhost:3000
|
||||
|
||||
GOOGLE_CLIENT_ID=
|
||||
GOOGLE_CLIENT_SECRET=
|
||||
|
||||
@@ -4,9 +4,6 @@ export async function GET(req: Request) {
|
||||
try {
|
||||
const data = await getIpInfo(req);
|
||||
|
||||
const i_p = extractRealIP(req.headers);
|
||||
console.log("自助ip", i_p);
|
||||
|
||||
return Response.json({
|
||||
ip: data.ip,
|
||||
city: data.city,
|
||||
@@ -18,7 +15,6 @@ export async function GET(req: Request) {
|
||||
lang: data.lang,
|
||||
device: data.device,
|
||||
browser: data.browser,
|
||||
i_p,
|
||||
});
|
||||
} catch (error) {
|
||||
return Response.json({ statusText: "Server error" }, { status: 500 });
|
||||
|
||||
@@ -8,6 +8,7 @@ services:
|
||||
NODE_ENV: production
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
AUTH_SECRET: ${AUTH_SECRET:-your-auth-secret}
|
||||
AUTH_URL: ${AUTH_URL}
|
||||
NEXT_PUBLIC_APP_URL: ${NEXT_PUBLIC_APP_URL}
|
||||
NEXT_PUBLIC_OPEN_SIGNUP: ${NEXT_PUBLIC_OPEN_SIGNUP}
|
||||
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
|
||||
|
||||
+44
-8
@@ -18,7 +18,7 @@ export async function getGeolocation(
|
||||
if (isVercel) {
|
||||
return geolocation(req);
|
||||
} else {
|
||||
return await getClientGeolocation(req, ip);
|
||||
return await getClientGeolocationWithIpApi(ip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,16 +44,52 @@ export async function getClientGeolocation(
|
||||
req,
|
||||
ip,
|
||||
): Promise<GeoLocation | null> {
|
||||
const new_headers = new Headers();
|
||||
new_headers.set("X-Forwarded-For", ip);
|
||||
new_headers.set("User-Agent", req.headers.get("user-agent") || "");
|
||||
const response = await fetch(`https://ip.wr.do/api?ip=${ip}`, {
|
||||
// signal: AbortSignal.timeout(3000),
|
||||
headers: new_headers,
|
||||
});
|
||||
// const new_headers = new Headers();
|
||||
// new_headers.set("X-Forwarded-For", ip);
|
||||
// new_headers.set("User-Agent", req.headers.get("user-agent") || "");
|
||||
const response = await fetch(`https://ip.wr.do/api?ip=${ip}`);
|
||||
if (!response.ok) return null;
|
||||
return await response.json();
|
||||
}
|
||||
export async function getClientGeolocationWithIpApi(ip: string) {
|
||||
const response = await fetch(`http://ip-api.com/json/${ip}`);
|
||||
if (!response.ok) return null;
|
||||
const res = await response.json();
|
||||
// {
|
||||
// "query": "154.64.226.29",
|
||||
// "status": "success",
|
||||
// "continent": "North America",
|
||||
// "continentCode": "NA",
|
||||
// "country": "United States",
|
||||
// "countryCode": "US",
|
||||
// "region": "CA",
|
||||
// "regionName": "California",
|
||||
// "city": "Los Angeles",
|
||||
// "district": "",
|
||||
// "zip": "90009",
|
||||
// "lat": 34.0549,
|
||||
// "lon": -118.243,
|
||||
// "timezone": "America/Los_Angeles",
|
||||
// "offset": -25200,
|
||||
// "currency": "USD",
|
||||
// "isp": "Cogent Communications",
|
||||
// "org": "NetLab Global",
|
||||
// "as": "AS51847 Nearoute Limited",
|
||||
// "asname": "NEAROUTE",
|
||||
// "mobile": true,
|
||||
// "proxy": true,
|
||||
// "hosting": false
|
||||
// }
|
||||
return {
|
||||
ip: res.query,
|
||||
country: res.country,
|
||||
region: res.region,
|
||||
city: res.city,
|
||||
latitude: res.lat,
|
||||
longitude: res.lon,
|
||||
timezone: res.timezone,
|
||||
};
|
||||
}
|
||||
|
||||
export function extractRealIP(headers: Headers): string {
|
||||
const ipHeaders = [
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user