* fix(invoice-inbox): include pdfjs worker file in function bundle After #407 landed and the DOMMatrix error was gone, the next pdfjs failure surfaced in prod logs: Setting up fake worker failed: "Cannot find module '/var/task/node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs'..." pdfjs loads its worker module via dynamic import at runtime, which Next's tracer can't see. With pdfjs-dist marked as a server external package the main pdf.mjs ships but the worker file gets pruned. Force-include it via outputFileTracingIncludes for any /api/extensions/ext/** route, since that's where invoice-inbox dispatches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor: narrow pdfjs worker tracing to invoice-inbox sub-path Per Greptile review on #408. Other extensions don't use pdfjs and shouldn't pay the ~1 MB worker cost. In practice all extension routes share one catch-all bundle, so this is more about clarity of intent than bundle size today, but future-proofs against per-segment bundling. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
81 lines
2.6 KiB
TypeScript
81 lines
2.6 KiB
TypeScript
import type { NextConfig } from "next";
|
|
|
|
const isDev = process.env.NODE_ENV === "development";
|
|
|
|
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL ?? "";
|
|
|
|
const activepiecesUrl = process.env.ACTIVEPIECES_URL ?? "";
|
|
|
|
const cspDirectives = [
|
|
"default-src 'self'",
|
|
`connect-src 'self' ${supabaseUrl} https://*.supabase.co wss://*.supabase.co https://*.enablebanking.com https://*.recapt.app`,
|
|
`style-src 'self' 'unsafe-inline' https://*.enablebanking.com`,
|
|
`script-src 'self' 'unsafe-inline'${isDev ? " 'unsafe-eval'" : ""} https://*.enablebanking.com https://cdn.recapt.app`,
|
|
"img-src 'self' data: blob: https:",
|
|
"font-src 'self'",
|
|
"worker-src 'self' blob:",
|
|
`frame-src 'self'${activepiecesUrl ? ` ${activepiecesUrl}` : ""}`,
|
|
"frame-ancestors 'none'",
|
|
].join("; ");
|
|
|
|
const nextConfig: NextConfig = {
|
|
output: 'standalone',
|
|
// Keep pdfjs-dist out of the bundle. The legacy build references
|
|
// @napi-rs/canvas at module load and breaks Vercel's bundling step.
|
|
// Text extraction works in pure Node once DOM globals are stubbed at
|
|
// module load (see extensions/general/invoice-inbox/lib/extract-invoice-fields.ts).
|
|
serverExternalPackages: ['pdfjs-dist'],
|
|
// Force the pdfjs worker file into the function bundle. Next.js's tracer
|
|
// can't see it (loaded dynamically by name), so without this it's missing
|
|
// in /var/task and getDocument() fails with "Setting up fake worker failed".
|
|
// Scoped to the invoice-inbox sub-path — other extensions don't use pdfjs
|
|
// and shouldn't pay the ~1 MB worker cost.
|
|
outputFileTracingIncludes: {
|
|
'/api/extensions/ext/invoice-inbox/**': ['./node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs'],
|
|
},
|
|
async redirects() {
|
|
return [
|
|
{
|
|
source: '/nyckeltal',
|
|
destination: '/kpi',
|
|
permanent: true,
|
|
},
|
|
]
|
|
},
|
|
async headers() {
|
|
return [
|
|
{
|
|
source: "/(.*)",
|
|
headers: [
|
|
{
|
|
key: "Strict-Transport-Security",
|
|
value: "max-age=63072000; includeSubDomains; preload",
|
|
},
|
|
{
|
|
key: "X-Frame-Options",
|
|
value: "DENY",
|
|
},
|
|
{
|
|
key: "X-Content-Type-Options",
|
|
value: "nosniff",
|
|
},
|
|
{
|
|
key: "Referrer-Policy",
|
|
value: "strict-origin-when-cross-origin",
|
|
},
|
|
{
|
|
key: "Permissions-Policy",
|
|
value: "camera=(), microphone=(), geolocation=(), payment=()",
|
|
},
|
|
{
|
|
key: "Content-Security-Policy",
|
|
value: cspDirectives,
|
|
},
|
|
],
|
|
},
|
|
];
|
|
},
|
|
};
|
|
|
|
export default nextConfig;
|