diff --git a/package.json b/package.json index 6dbc321d..28bd1610 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homepage", - "version": "1.41.2", + "version": "1.41.3", "private": true, "type": "module", "scripts": { diff --git a/src/lib/server/bible.ts b/src/lib/server/bible.ts index a42634cd..de5f9e88 100644 --- a/src/lib/server/bible.ts +++ b/src/lib/server/bible.ts @@ -1,5 +1,5 @@ import { readFileSync } from 'fs'; -import { resolve } from 'path'; +import { resolveStaticAsset } from './staticAsset'; export interface BibleVerse { bookName: string; @@ -13,7 +13,7 @@ export interface BibleVerse { const versesCache = new Map(); export function loadVersesFromFile(tsvPath?: string): BibleVerse[] { - const filePath = tsvPath ?? resolve('static/allioli.tsv'); + const filePath = tsvPath ?? resolveStaticAsset('allioli.tsv'); const cached = versesCache.get(filePath); if (cached) return cached; diff --git a/src/lib/server/properBibleFallback.ts b/src/lib/server/properBibleFallback.ts index 9c32fe88..276fc920 100644 --- a/src/lib/server/properBibleFallback.ts +++ b/src/lib/server/properBibleFallback.ts @@ -1,12 +1,12 @@ -import { resolve } from 'path'; import { translateRefToTarget } from './bibleRefLatin'; import { lookupReference } from './bible'; +import { resolveStaticAsset } from './staticAsset'; export type FallbackLang = 'en' | 'de'; -const TSV_PATH: Record = { - en: 'static/drb.tsv', - de: 'static/allioli.tsv' +const TSV_NAME: Record = { + en: 'drb.tsv', + de: 'allioli.tsv' }; // Latin propers often cite successive verses in compact form like @@ -40,7 +40,7 @@ function stripPsalmSuperscription(text: string, lang: FallbackLang): string { export function fetchLocalFromBible(refs: string[], lang: FallbackLang): string | null { if (!refs || refs.length === 0) return null; - const tsvPath = resolve(TSV_PATH[lang]); + const tsvPath = resolveStaticAsset(TSV_NAME[lang]); const collected: string[] = []; for (const rawRef of refs) { for (const seg of splitCompoundRef(rawRef)) { diff --git a/src/lib/server/staticAsset.ts b/src/lib/server/staticAsset.ts new file mode 100644 index 00000000..bb2941f6 --- /dev/null +++ b/src/lib/server/staticAsset.ts @@ -0,0 +1,19 @@ +import { fileURLToPath } from 'node:url'; +import { dirname, resolve } from 'node:path'; +import { existsSync } from 'node:fs'; + +const MODULE_DIR = dirname(fileURLToPath(import.meta.url)); + +// adapter-node bundles server code into build/server/chunks/*.js; +// public static assets end up at build/client/. Resolve there first +// so deploys that sit `build/` at any prefix work without a CWD. +const BUILD_STATIC = resolve(MODULE_DIR, '..', '..', 'client'); + +// Dev (vite/vite-node): CWD is the project root, raw static/ lives there. +const DEV_STATIC = resolve('static'); + +export function resolveStaticAsset(name: string): string { + const bundled = resolve(BUILD_STATIC, name); + if (existsSync(bundled)) return bundled; + return resolve(DEV_STATIC, name); +} diff --git a/src/routes/api/[faithLang=faithLang]/bibel/[reference]/+server.ts b/src/routes/api/[faithLang=faithLang]/bibel/[reference]/+server.ts index 965bfa87..ba029170 100644 --- a/src/routes/api/[faithLang=faithLang]/bibel/[reference]/+server.ts +++ b/src/routes/api/[faithLang=faithLang]/bibel/[reference]/+server.ts @@ -1,11 +1,11 @@ import { json, error } from '@sveltejs/kit'; import type { RequestHandler } from './$types'; import { lookupReference } from '$lib/server/bible'; -import { resolve } from 'path'; +import { resolveStaticAsset } from '$lib/server/staticAsset'; const tsvFiles: Record = { - glaube: 'static/allioli.tsv', - faith: 'static/drb.tsv' + glaube: 'allioli.tsv', + faith: 'drb.tsv' }; export const GET: RequestHandler = async ({ params }) => { @@ -15,7 +15,7 @@ export const GET: RequestHandler = async ({ params }) => { return error(400, 'Missing reference parameter'); } - const tsvPath = resolve(tsvFiles[params.faithLang]); + const tsvPath = resolveStaticAsset(tsvFiles[params.faithLang]); try { const result = lookupReference(reference, tsvPath);