Bundle PDF.js worker via Vite ?worker so it ships as a .js asset
CI / vuln-scan (push) Successful in 14s
CI / sast (push) Successful in 10s
CI / test (push) Successful in 26s
CI / lint (push) Successful in 28s
CI / secrets-scan (push) Successful in 5s
CI / build-images (push) Successful in 1m57s
CI / image-scan (push) Successful in 50s
CI / push (push) Successful in 32s

Production deploy returned the worker module with
Content-Type: application/octet-stream — nginx's bundled mime.types
doesn't map .mjs and X-Content-Type-Options: nosniff stopped Firefox
from executing it, so PDFs failed with "Setting up fake worker failed".

Switch the worker import from ?url to ?worker and assign workerPort, so
Vite emits the worker as a regular hashed .js chunk that nginx already
serves correctly. Also add a nginx fallback that maps .mjs to
text/javascript for any future module assets, and include text/javascript
in gzip_types.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 23:21:35 -07:00
parent 3087efb5db
commit 8e1bac5430
4 changed files with 15 additions and 5 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "tehriehlbudget-backend",
"version": "0.3.0",
"version": "0.3.1",
"description": "",
"author": "",
"private": true,
+11 -1
View File
@@ -6,9 +6,19 @@ server {
# Compress text-ish assets on the fly
gzip on;
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
gzip_types text/plain text/css text/javascript application/javascript application/json image/svg+xml;
gzip_min_length 1024;
# nginx's bundled mime.types in this image still maps `.mjs` to
# application/octet-stream, which browsers refuse to execute as a module
# (especially with X-Content-Type-Options: nosniff). Force the JS MIME
# type for any `.mjs` so module workers / dynamic imports work.
location ~* \.mjs$ {
types { } default_type text/javascript;
add_header Cache-Control "public, max-age=31536000, immutable" always;
try_files $uri =404;
}
# Block dotfiles served from the static root
location ~ /\. {
deny all;
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "tehriehlbudget-frontend",
"private": true,
"version": "0.3.0",
"version": "0.3.1",
"type": "module",
"scripts": {
"dev": "vite",
@@ -1,4 +1,4 @@
import { pdfjs } from 'react-pdf';
import workerSrc from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
import PdfWorker from 'pdfjs-dist/build/pdf.worker.min.mjs?worker';
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
pdfjs.GlobalWorkerOptions.workerPort = new PdfWorker();