fix(runtime-config): resolver MUSIC_DIR en tiempo de ejecución y no hornearlo en build; endpoints usan env absoluto o public fallback
All checks were successful
build-and-deploy / build (push) Successful in 21s
build-and-deploy / deploy (push) Successful in 3s

This commit is contained in:
2025-08-10 03:03:22 -06:00
parent 81330de97e
commit e3e7374096
3 changed files with 9 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
import { promises as fs } from 'fs'
import { join } from 'path'
import { join, resolve, isAbsolute } from 'path'
export default defineEventHandler(async (event) => {
try {
@@ -9,10 +9,12 @@ export default defineEventHandler(async (event) => {
console.log(`[MUSIC API] Music list request from ${realIP}`)
const config = useRuntimeConfig()
// Prefer absolute dir computed at build time; fallback to env or public path
const defaultPublicPath = config.public?.musicPath || '/music'
const publicRel = defaultPublicPath.replace(/^\//, '')
const musicDir = config.musicDirAbs || process.env.MUSIC_DIR || join(process.cwd(), 'public', publicRel)
const envDir = process.env.MUSIC_DIR
const musicDir = envDir
? (isAbsolute(envDir) ? envDir : resolve(process.cwd(), envDir))
: join(process.cwd(), 'public', publicRel)
// Check if music directory exists
try {