Docker 런타임 환경 변수 우선 적용
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createHmac, timingSafeEqual } from 'node:crypto'
|
||||
import { createError, deleteCookie, getCookie, setCookie } from 'h3'
|
||||
import { getRuntimeEnvValue } from './runtime-env'
|
||||
|
||||
const adminSessionCookieName = 'sori_admin_session'
|
||||
const sessionMaxAge = 60 * 60 * 12
|
||||
@@ -9,16 +10,16 @@ const sessionMaxAge = 60 * 60 * 12
|
||||
* @returns {string} 세션 서명 비밀값
|
||||
*/
|
||||
const getSessionSecret = () => {
|
||||
const config = useRuntimeConfig()
|
||||
const adminPassword = getRuntimeEnvValue('ADMIN_PASSWORD', 'adminPassword')
|
||||
|
||||
if (!config.adminPassword) {
|
||||
if (!adminPassword) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: '관리자 비밀번호 환경 변수가 없습니다.'
|
||||
})
|
||||
}
|
||||
|
||||
return config.adminPassword
|
||||
return adminPassword
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createHmac, timingSafeEqual } from 'node:crypto'
|
||||
import { createError, deleteCookie, getCookie, setCookie } from 'h3'
|
||||
import { getRuntimeEnvValue } from './runtime-env'
|
||||
|
||||
const memberSessionCookieName = 'sori_member_session'
|
||||
const sessionMaxAge = 60 * 60 * 24 * 14
|
||||
@@ -9,8 +10,7 @@ const sessionMaxAge = 60 * 60 * 24 * 14
|
||||
* @returns {string} 세션 서명 비밀값
|
||||
*/
|
||||
const getSessionSecret = () => {
|
||||
const config = useRuntimeConfig()
|
||||
const sessionSecret = String(config.memberSessionSecret || '').trim()
|
||||
const sessionSecret = getRuntimeEnvValue('MEMBER_SESSION_SECRET', 'memberSessionSecret').trim()
|
||||
|
||||
if (!sessionSecret) {
|
||||
throw createError({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createError } from 'h3'
|
||||
import { getRuntimeEnvValue } from './runtime-env'
|
||||
|
||||
/**
|
||||
* Resend가 서버 설정으로 사용 가능한지
|
||||
@@ -6,8 +7,8 @@ import { createError } from 'h3'
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export const isResendConfigured = (config) => {
|
||||
const key = String(config?.resendApiKey || '').trim()
|
||||
const from = String(config?.resendFromEmail || '').trim()
|
||||
const key = getRuntimeEnvValue('RESEND_API_KEY', 'resendApiKey', String(config?.resendApiKey || '')).trim()
|
||||
const from = getRuntimeEnvValue('RESEND_FROM_EMAIL', 'resendFromEmail', String(config?.resendFromEmail || '')).trim()
|
||||
return Boolean(key && from)
|
||||
}
|
||||
|
||||
|
||||
36
server/utils/runtime-env.js
Normal file
36
server/utils/runtime-env.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 서버 런타임 환경 변수 값을 조회한다.
|
||||
* @param {string} envName - process.env 변수명
|
||||
* @param {string} configName - Nuxt runtimeConfig 키
|
||||
* @param {string} fallback - 기본값
|
||||
* @returns {string} 환경 변수 값
|
||||
*/
|
||||
export const getRuntimeEnvValue = (envName, configName, fallback = '') => {
|
||||
const directValue = process.env[envName]
|
||||
if (typeof directValue === 'string' && directValue.length > 0) {
|
||||
return directValue
|
||||
}
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const configValue = config?.[configName]
|
||||
|
||||
return typeof configValue === 'string' && configValue.length > 0
|
||||
? configValue
|
||||
: fallback
|
||||
}
|
||||
|
||||
/**
|
||||
* 숫자형 서버 런타임 환경 변수 값을 조회한다.
|
||||
* @param {string} envName - process.env 변수명
|
||||
* @param {string} configName - Nuxt runtimeConfig 키
|
||||
* @param {number} fallback - 기본값
|
||||
* @returns {number} 환경 변수 숫자 값
|
||||
*/
|
||||
export const getRuntimeEnvNumber = (envName, configName, fallback) => {
|
||||
const value = getRuntimeEnvValue(envName, configName, '')
|
||||
const parsed = Number(value)
|
||||
|
||||
return Number.isFinite(parsed) && parsed > 0
|
||||
? parsed
|
||||
: fallback
|
||||
}
|
||||
Reference in New Issue
Block a user