25 lines
610 B
TypeScript
25 lines
610 B
TypeScript
import { Pool } from 'pg';
|
|
import { config } from 'dotenv';
|
|
|
|
// Load environment variables based on the environment
|
|
if (process.env.NODE_ENV === 'production') {
|
|
config({ path: '.env.production' });
|
|
} else {
|
|
config({ path: '.env.local' });
|
|
}
|
|
|
|
const connectionString = process.env.NODE_ENV === 'production'
|
|
? process.env.SUPABASE_URL
|
|
: process.env.DATABASE_URL;
|
|
|
|
console.log('Using connection string:', connectionString);
|
|
|
|
if (!connectionString) {
|
|
throw new Error('Database connection URL is not set in environment variables');
|
|
}
|
|
|
|
const pool = new Pool({
|
|
connectionString,
|
|
});
|
|
|
|
export default pool; |