Server runs from build output dir where CWD-relative `static/*.tsv` misses — adapter-node ships static assets at build/client/. New resolveStaticAsset() helper uses import.meta.url to find the bundled location, falls back to <cwd>/static/ in dev. Fixes ENOENT on drb.tsv/allioli.tsv after deploy.
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "homepage",
|
||||
"version": "1.41.2",
|
||||
"version": "1.41.3",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -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<string, BibleVerse[]>();
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -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<FallbackLang, string> = {
|
||||
en: 'static/drb.tsv',
|
||||
de: 'static/allioli.tsv'
|
||||
const TSV_NAME: Record<FallbackLang, string> = {
|
||||
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)) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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<string, string> = {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user