Files
Sven laptop e169e37b5e
Build and Push Docker Images / detect-changes (push) Successful in 20s
Build and Push Docker Images / build-auth-api (push) Successful in 2m2s
Build and Push Docker Images / build-employee-api (push) Successful in 2m2s
Build and Push Docker Images / build-transit-api (push) Successful in 2m8s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m58s
Build and Push Docker Images / build-monitoring-ui (push) Has been cancelled
Build and Push Docker Images / build-admin-ui (push) Has been cancelled
Build and Push Docker Images / deploy-test-node (push) Has been cancelled
Refactored all api endpoints to /bus/xxxxx
2026-09-24 20:20:43 +02:00

43 lines
1.2 KiB
JavaScript

const { Pool } = require('pg');
require('dotenv').config();
const pool = new Pool({
host: process.env.PG_HOST,
port: process.env.PG_PORT,
user: process.env.PG_USER,
password: process.env.PG_PASS,
database: process.env.PG_DB,
max: 10,
idleTimeoutMillis: 30000
});
pool.query('SELECT 1')
.then(() => console.log('PostgreSQL connection OK'))
.catch(err => {
console.error('PostgreSQL connection FAILED');
console.error(err);
const url = process.env.ERROR_LOG_API_URL || 'https://error.xtransit.testinstance.nl/error_log';
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 5000);
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-internal-api-key': process.env.INTERNAL_API_KEY || '',
},
body: JSON.stringify({
service: 'employee_api',
partofservice: 'startup: db connection',
error: err.stack || err.message || String(err),
}),
signal: controller.signal,
}).catch(() => {})
.finally(() => {
clearTimeout(timer);
process.exit(1);
});
});
module.exports = {
query: (text, params) => pool.query(text, params),
pool
};