fix: db connection string parse override and add debug to main app
Build and Deploy (Gitea Actions) / build-and-deploy (push) Successful in 2m37s
Details
Build and Deploy (Gitea Actions) / build-and-deploy (push) Successful in 2m37s
Details
This commit is contained in:
parent
788639d7aa
commit
2f26053a8d
|
|
@ -2,22 +2,25 @@ import { Pool } from 'pg';
|
||||||
|
|
||||||
const connectionString = process.env.DATABASE_URL || 'postgresql://agendapro:agendapro123@localhost:5432/agendapro';
|
const connectionString = process.env.DATABASE_URL || 'postgresql://agendapro:agendapro123@localhost:5432/agendapro';
|
||||||
|
|
||||||
// Extract password from connectionString manually just to check, or provide a fallback
|
let dbConfig: any = {
|
||||||
let fallbackPassword = process.env.DB_PASSWORD || process.env.POSTGRES_PASSWORD || '';
|
|
||||||
try {
|
|
||||||
const url = new URL(connectionString);
|
|
||||||
if (!url.password) {
|
|
||||||
fallbackPassword = process.env.DB_PASSWORD || process.env.POSTGRES_PASSWORD || 'agendapro123';
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
const pool = new Pool({
|
|
||||||
connectionString,
|
|
||||||
password: fallbackPassword,
|
|
||||||
max: 20,
|
max: 20,
|
||||||
idleTimeoutMillis: 30000,
|
idleTimeoutMillis: 30000,
|
||||||
connectionTimeoutMillis: 2000,
|
connectionTimeoutMillis: 2000,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = new URL(connectionString);
|
||||||
|
dbConfig.host = url.hostname;
|
||||||
|
dbConfig.port = parseInt(url.port) || 5432;
|
||||||
|
dbConfig.user = url.username || 'postgres';
|
||||||
|
dbConfig.password = url.password || process.env.DB_PASSWORD || process.env.POSTGRES_PASSWORD || 'agendapro123';
|
||||||
|
dbConfig.database = url.pathname.replace('/', '') || 'agendapro';
|
||||||
|
} catch (e) {
|
||||||
|
// Se não for uma URL válida, usa a string diretamente
|
||||||
|
dbConfig.connectionString = connectionString;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pool = new Pool(dbConfig);
|
||||||
|
|
||||||
pool.on('error', (err) => {
|
pool.on('error', (err) => {
|
||||||
console.error('Unexpected error on idle client', err);
|
console.error('Unexpected error on idle client', err);
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,6 @@ export async function POST(req: Request) {
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Login error:', error);
|
console.error('Login error:', error);
|
||||||
return NextResponse.json({ error: 'Erro interno do servidor' }, { status: 500 });
|
return NextResponse.json({ error: 'Erro interno do servidor', details: error.message }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ export default function LoginPage() {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
setError(data.error || 'Erro ao realizar login');
|
setError(data.error + (data.details ? ` (${data.details})` : '') || 'Erro ao realizar login');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,25 @@ import { Pool } from 'pg';
|
||||||
|
|
||||||
const connectionString = process.env.DATABASE_URL || 'postgresql://agendapro:agendapro123@localhost:5432/agendapro';
|
const connectionString = process.env.DATABASE_URL || 'postgresql://agendapro:agendapro123@localhost:5432/agendapro';
|
||||||
|
|
||||||
// Extract password from connectionString manually just to check, or provide a fallback
|
let dbConfig: any = {
|
||||||
let fallbackPassword = process.env.DB_PASSWORD || process.env.POSTGRES_PASSWORD || '';
|
|
||||||
try {
|
|
||||||
const url = new URL(connectionString);
|
|
||||||
if (!url.password) {
|
|
||||||
fallbackPassword = process.env.DB_PASSWORD || process.env.POSTGRES_PASSWORD || 'agendapro123';
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
const pool = new Pool({
|
|
||||||
connectionString,
|
|
||||||
password: fallbackPassword,
|
|
||||||
max: 20,
|
max: 20,
|
||||||
idleTimeoutMillis: 30000,
|
idleTimeoutMillis: 30000,
|
||||||
connectionTimeoutMillis: 2000,
|
connectionTimeoutMillis: 2000,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = new URL(connectionString);
|
||||||
|
dbConfig.host = url.hostname;
|
||||||
|
dbConfig.port = parseInt(url.port) || 5432;
|
||||||
|
dbConfig.user = url.username || 'postgres';
|
||||||
|
dbConfig.password = url.password || process.env.DB_PASSWORD || process.env.POSTGRES_PASSWORD || 'agendapro123';
|
||||||
|
dbConfig.database = url.pathname.replace('/', '') || 'agendapro';
|
||||||
|
} catch (e) {
|
||||||
|
// Se não for uma URL válida, usa a string diretamente
|
||||||
|
dbConfig.connectionString = connectionString;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pool = new Pool(dbConfig);
|
||||||
|
|
||||||
pool.on('error', (err) => {
|
pool.on('error', (err) => {
|
||||||
console.error('Unexpected error on idle client', err);
|
console.error('Unexpected error on idle client', err);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue