优化无法登录的错误
This commit is contained in:
@@ -31,8 +31,19 @@ function normalizeGeo(geo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getLocation(target) {
|
async function getLocation(target) {
|
||||||
// Normalize target (strip port if present)
|
// Normalize target (strip port if present, handle IPv6 brackets)
|
||||||
const cleanTarget = target.split(':')[0];
|
let cleanTarget = target;
|
||||||
|
if (cleanTarget.startsWith('[')) {
|
||||||
|
const closingBracket = cleanTarget.indexOf(']');
|
||||||
|
if (closingBracket !== -1) {
|
||||||
|
cleanTarget = cleanTarget.substring(1, closingBracket);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const parts = cleanTarget.split(':');
|
||||||
|
if (parts.length === 2) {
|
||||||
|
cleanTarget = parts[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Check if we already have this IP/Domain in DB (FASTEST)
|
// 1. Check if we already have this IP/Domain in DB (FASTEST)
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1090,7 +1090,21 @@ async function getOverview(force = false) {
|
|||||||
// --- Add Geo Information to Servers ---
|
// --- Add Geo Information to Servers ---
|
||||||
const geoServers = await Promise.all(overview.servers.map(async (server) => {
|
const geoServers = await Promise.all(overview.servers.map(async (server) => {
|
||||||
const realInstance = server.originalInstance || prometheusService.resolveToken(server.instance);
|
const realInstance = server.originalInstance || prometheusService.resolveToken(server.instance);
|
||||||
const cleanIp = realInstance.split(':')[0];
|
// Helper to get host from instance (handles IPv6 with brackets, IPv4:port, etc.)
|
||||||
|
let cleanIp = realInstance;
|
||||||
|
if (cleanIp.startsWith('[')) {
|
||||||
|
const closingBracket = cleanIp.indexOf(']');
|
||||||
|
if (closingBracket !== -1) {
|
||||||
|
cleanIp = cleanIp.substring(1, closingBracket);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const parts = cleanIp.split(':');
|
||||||
|
// If exactly one colon, it's likely IPv4:port or host:port
|
||||||
|
if (parts.length === 2) {
|
||||||
|
cleanIp = parts[0];
|
||||||
|
}
|
||||||
|
// If more than 1 colon and no brackets, it's an IPv6 without port - keep as is
|
||||||
|
}
|
||||||
|
|
||||||
let geoData = null;
|
let geoData = null;
|
||||||
try {
|
try {
|
||||||
@@ -1417,16 +1431,27 @@ async function broadcastMetrics() {
|
|||||||
async function start() {
|
async function start() {
|
||||||
try {
|
try {
|
||||||
console.log('🔧 Initializing services...');
|
console.log('🔧 Initializing services...');
|
||||||
// Ensure DB is ready before starting anything else
|
|
||||||
|
// 1. Initial check
|
||||||
|
await checkDb();
|
||||||
|
|
||||||
|
// 2. Automated repair/migration
|
||||||
try {
|
try {
|
||||||
const dbFixed = await checkAndFixDatabase();
|
const dbFixed = await checkAndFixDatabase();
|
||||||
if (dbFixed) {
|
if (dbFixed) {
|
||||||
// Re-run the local checkDb() to update isDbInitialized and other status variables
|
// Refresh state after fix
|
||||||
await checkDb();
|
await checkDb();
|
||||||
|
if (isDbInitialized) {
|
||||||
|
console.log(' ✅ Database integrity verified and initialized');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (dbErr) {
|
} catch (dbErr) {
|
||||||
console.warn('⚠️ Database initialization check encountered an error:', dbErr.message);
|
console.error('❌ Critical database initialization error:', dbErr.message);
|
||||||
// We don't necessarily crash here, but users will see the setup screen if isDbInitialized is false
|
// If we have an .env but can't connect, this is a fatal config error
|
||||||
|
if (fs.existsSync(path.join(__dirname, '..', '.env'))) {
|
||||||
|
console.error(' Please check your MYSQL settings in .env');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start services
|
// Start services
|
||||||
@@ -1456,4 +1481,12 @@ async function start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.on('unhandledRejection', (reason, promise) => {
|
||||||
|
console.error('[System] Unhandled Rejection at:', promise, 'reason:', reason);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('uncaughtException', (err) => {
|
||||||
|
console.error('[System] Uncaught Exception:', err);
|
||||||
|
});
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
|||||||
Reference in New Issue
Block a user