1 Commits

Author SHA1 Message Date
3a4aabff1d fix: bundle PDF.js worker locally to fix CDN loading issues
Some checks failed
Create Release / release (push) Has been cancelled
- Add postinstall script to copy worker to static/
- Update Dockerfile to copy worker during build
- Update file-processor to try local worker first, fallback to CDN
- Bump version to 0.4.11
2026-01-03 22:16:19 +01:00
5 changed files with 23 additions and 5 deletions

3
.gitignore vendored
View File

@@ -42,3 +42,6 @@ dev.env
backend/vessel-backend
data/
backend/data-dev/
# Generated files
frontend/static/pdf.worker.min.mjs

View File

@@ -18,7 +18,7 @@ import (
)
// Version is set at build time via -ldflags, or defaults to dev
var Version = "0.4.10"
var Version = "0.4.11"
func getEnvOrDefault(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {

View File

@@ -12,6 +12,10 @@ RUN npm ci
# Copy source code
COPY . .
# Copy PDF.js worker to static directory for local serving
# This avoids CDN dependency and CORS issues with ESM modules
RUN cp node_modules/pdfjs-dist/build/pdf.worker.min.mjs static/
# Build the application
RUN npm run build

View File

@@ -1,6 +1,6 @@
{
"name": "vessel",
"version": "0.4.10",
"version": "0.4.11",
"private": true,
"type": "module",
"scripts": {
@@ -11,7 +11,8 @@
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
"test:coverage": "vitest run --coverage",
"postinstall": "cp node_modules/pdfjs-dist/build/pdf.worker.min.mjs static/ 2>/dev/null || true"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^4.0.0",

View File

@@ -150,8 +150,18 @@ async function loadPdfJs(): Promise<typeof import('pdfjs-dist')> {
try {
pdfjsLib = await import('pdfjs-dist');
// Set worker source using CDN for reliability
pdfjsLib.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.mjs`;
// Use locally bundled worker (copied to static/ during build)
// Falls back to CDN if local worker isn't available
const localWorkerPath = '/pdf.worker.min.mjs';
const cdnWorkerPath = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.mjs`;
// Try local first, with CDN fallback
try {
const response = await fetch(localWorkerPath, { method: 'HEAD' });
pdfjsLib.GlobalWorkerOptions.workerSrc = response.ok ? localWorkerPath : cdnWorkerPath;
} catch {
pdfjsLib.GlobalWorkerOptions.workerSrc = cdnWorkerPath;
}
return pdfjsLib;
} catch (error) {