修复无法正常登录的问题
This commit is contained in:
@@ -582,25 +582,28 @@ app.get('/api/metrics/overview', async (req, res) => {
|
||||
|
||||
// --- Add Geo Information to Servers ---
|
||||
const geoServers = await Promise.all(overview.servers.map(async (server) => {
|
||||
// The original IP is masked in the response from prometheusService.getOverviewMetrics
|
||||
// But we can get it back from serverIdMap in prometheusService if we are on the same process
|
||||
// Actually, prometheusService needs to provide a way to get the real IP back.
|
||||
// Or we can just modify getOverviewMetrics to return the real IP for internal use.
|
||||
|
||||
// Let's look at prometheusService.js's getServerIdMap logic
|
||||
const realInstance = prometheusService.resolveToken(server.instance);
|
||||
const cleanIp = realInstance.split(':')[0];
|
||||
|
||||
// Attempt to get location
|
||||
const location = await geoService.getLocation(cleanIp);
|
||||
if (location) {
|
||||
return {
|
||||
...server,
|
||||
country: location.country,
|
||||
countryName: location.country_name,
|
||||
lat: location.latitude,
|
||||
lng: location.longitude
|
||||
};
|
||||
// Try to get from DB cache only (fast)
|
||||
try {
|
||||
const [rows] = await db.query('SELECT * FROM server_locations WHERE ip = ?', [cleanIp]);
|
||||
if (rows.length > 0) {
|
||||
const location = rows[0];
|
||||
return {
|
||||
...server,
|
||||
country: location.country,
|
||||
countryName: location.country_name,
|
||||
city: location.city,
|
||||
lat: location.latitude,
|
||||
lng: location.longitude
|
||||
};
|
||||
} else {
|
||||
// Trigger background resolution for future requests
|
||||
geoService.getLocation(cleanIp).catch(() => {});
|
||||
}
|
||||
} catch (e) {
|
||||
// DB error, skip geo for now
|
||||
}
|
||||
return server;
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user