Files
sori.studio/server/repositories/postgres-client.js
zenn de767095ba v1.10.88 품질·보안 개선과 미디어 카탈로그 database 전환을 반영한다.
세션·로그인 제한, ZIP/업로드 스트리밍, CSP 최소 강제와 Report-Only, Playwright 격리 검증을 추가하고 미디어 목록을 reconcile 후 database 모드로 고정한다.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-22 11:05:40 +09:00

37 lines
811 B
JavaScript

import postgres from 'postgres'
import { getRuntimeEnvValue } from '../utils/runtime-env.js'
let client = null
/**
* 현재 실행 환경이 운영인지 확인한다.
* @returns {boolean} 운영 환경 여부
*/
const isProductionRuntime = () => process.env.NODE_ENV === 'production'
/**
* PostgreSQL 클라이언트 조회
* @returns {ReturnType<typeof postgres> | null} PostgreSQL 클라이언트
*/
export const getPostgresClient = () => {
const databaseUrl = getRuntimeEnvValue('DATABASE_URL', 'databaseUrl').trim()
if (!databaseUrl) {
if (isProductionRuntime()) {
throw new Error('DATABASE_URL_REQUIRED')
}
return null
}
if (!client) {
client = postgres(databaseUrl, {
max: 5,
idle_timeout: 20,
connect_timeout: 10
})
}
return client
}