Refactor Dockerfile to optimize layering, embed entrypoint migration tools and compute worker as deployable bundles, and merge only required dependencies for runtime scripts. Add docker/entrypoint-migration-tools package and update workspace configuration. Refactor PDF parsing to resolve standard font data path robustly at runtime. Update dependencies and output config for Next.js standalone mode. Enhance entrypoint script to launch embedded compute worker from deployed bundle. - Dockerfile now deploys migration tools and compute worker as separate bundles - compute/core/pdf uses new pdfjs-runtime utility for robust font path resolution - docker/entrypoint-migration-tools added for migration script dependencies - scripts/openreader-entrypoint.mjs launches embedded worker from deployed bundle - next.config.ts enables standalone output and includes standard_fonts in tracing - Dependency updates across package.json and compute/worker/package.json BREAKING CHANGE: Docker image structure and runtime entrypoint logic have changed; custom deployment scripts or Docker overrides may require updates.
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
import type { NextConfig } from "next";
|
|
|
|
const securityHeaders = [
|
|
{ key: 'X-Content-Type-Options', value: 'nosniff' },
|
|
{ key: 'X-Frame-Options', value: 'SAMEORIGIN' },
|
|
{
|
|
key: 'Content-Security-Policy',
|
|
value: "frame-ancestors 'self' https://*.huggingface.co https://huggingface.co",
|
|
},
|
|
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
|
|
{ key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=()' },
|
|
{
|
|
key: 'Strict-Transport-Security',
|
|
value: 'max-age=63072000; includeSubDomains; preload',
|
|
},
|
|
];
|
|
|
|
const bundleWorkerCompute = true;
|
|
const serverExternalPackages = [
|
|
'@napi-rs/canvas',
|
|
'better-sqlite3',
|
|
'ffmpeg-static',
|
|
...(!bundleWorkerCompute ? ['onnxruntime-node', '@huggingface/tokenizers'] : []),
|
|
];
|
|
|
|
const nextConfig: NextConfig = {
|
|
output: 'standalone',
|
|
async headers() {
|
|
return [
|
|
{
|
|
// Apply security headers to all routes
|
|
source: '/(.*)',
|
|
headers: securityHeaders,
|
|
},
|
|
];
|
|
},
|
|
turbopack: {
|
|
resolveAlias: {
|
|
canvas: '@napi-rs/canvas',
|
|
},
|
|
},
|
|
transpilePackages: [],
|
|
serverExternalPackages,
|
|
outputFileTracingIncludes: {
|
|
'/api/audiobook': [
|
|
'./node_modules/ffmpeg-static/ffmpeg',
|
|
],
|
|
'/api/audiobook/chapter': [
|
|
'./node_modules/ffmpeg-static/ffmpeg',
|
|
],
|
|
'/api/tts/segments/ensure': [
|
|
'./node_modules/ffmpeg-static/ffmpeg',
|
|
],
|
|
'/api/documents/blob/preview/ensure': [
|
|
'./node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs',
|
|
'./node_modules/pdfjs-dist/standard_fonts/**/*',
|
|
],
|
|
'/api/documents/blob/preview/presign': [
|
|
'./node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs',
|
|
'./node_modules/pdfjs-dist/standard_fonts/**/*',
|
|
],
|
|
'/api/documents/blob/preview/fallback': [
|
|
'./node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs',
|
|
'./node_modules/pdfjs-dist/standard_fonts/**/*',
|
|
],
|
|
},
|
|
outputFileTracingExcludes: {
|
|
'/*': [
|
|
'./docstore/**/*',
|
|
'./node_modules/onnxruntime-node/**/*',
|
|
'./node_modules/@huggingface/tokenizers/**/*',
|
|
],
|
|
},
|
|
webpack: (config, { isServer }) => {
|
|
if (isServer && bundleWorkerCompute) {
|
|
config.resolve.alias = {
|
|
...(config.resolve.alias || {}),
|
|
'@openreader/compute-core/local-runtime$': false,
|
|
'onnxruntime-node$': false,
|
|
'@huggingface/tokenizers$': false,
|
|
};
|
|
}
|
|
return config;
|
|
},
|
|
};
|
|
|
|
export default nextConfig;
|