refactor(package): remove unused Remotion scripts and update HttpServer for improved static file serving
- Removed obsolete Remotion preview and render scripts from package.json. - Updated HttpServer to enhance static file serving logic, ensuring proper handling of renderer paths in both development and production modes. - Added support for asarUnpack in package.json to facilitate unpacking of renderer files.
This commit is contained in:
parent
ce4116dd85
commit
ea66c34ce3
2 changed files with 30 additions and 35 deletions
|
|
@ -43,9 +43,6 @@
|
|||
"test:watch": "vitest",
|
||||
"test:coverage": "vitest run --coverage",
|
||||
"test:coverage:critical": "vitest run --coverage --config vitest.critical.config.ts",
|
||||
"remotion:preview": "remotion studio remotion/index.ts",
|
||||
"remotion:render": "remotion render remotion/index.ts DemoVideo out/demo.mp4",
|
||||
"remotion:render:gif": "remotion render remotion/index.ts DemoVideo out/demo.gif --image-format png",
|
||||
"standalone": "tsx src/main/standalone.ts",
|
||||
"standalone:build": "electron-vite build && vite build --config vite.standalone.config.ts",
|
||||
"standalone:start": "node dist-standalone/index.cjs"
|
||||
|
|
@ -56,7 +53,6 @@
|
|||
"@dnd-kit/utilities": "^3.2.2",
|
||||
"@fastify/cors": "^11.2.0",
|
||||
"@fastify/static": "^9.0.0",
|
||||
"@remotion/light-leaks": "4.0.421",
|
||||
"@tanstack/react-virtual": "^3.10.8",
|
||||
"date-fns": "^3.6.0",
|
||||
"electron-updater": "^6.7.3",
|
||||
|
|
@ -133,6 +129,9 @@
|
|||
"package.json"
|
||||
],
|
||||
"asar": true,
|
||||
"asarUnpack": [
|
||||
"out/renderer/**"
|
||||
],
|
||||
"npmRebuild": false,
|
||||
"extraMetadata": {
|
||||
"main": "dist-electron/main/index.cjs"
|
||||
|
|
|
|||
|
|
@ -24,12 +24,13 @@ const logger = createLogger('Service:HttpServer');
|
|||
*/
|
||||
function resolveRendererPath(): string | null {
|
||||
const candidates = [
|
||||
// Electron production paths
|
||||
join(__dirname, '../../../out/renderer'),
|
||||
join(__dirname, '../../renderer'),
|
||||
// Electron production (asarUnpack): app.asar.unpacked/out/renderer (real filesystem)
|
||||
join(__dirname, '../../out/renderer').replace('app.asar', 'app.asar.unpacked'),
|
||||
// Electron production (asar fallback): app.asar/out/renderer
|
||||
join(__dirname, '../../out/renderer'),
|
||||
// Standalone: dist-standalone/index.cjs → ../out/renderer
|
||||
join(__dirname, '../out/renderer'),
|
||||
// Fallback: relative to cwd (for standalone bundles)
|
||||
// Fallback: relative to cwd (dev mode, standalone)
|
||||
join(process.cwd(), 'out/renderer'),
|
||||
];
|
||||
|
||||
|
|
@ -89,38 +90,33 @@ export class HttpServer {
|
|||
});
|
||||
}
|
||||
|
||||
// Register static file serving and SPA fallback (production only)
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
if (!isDev) {
|
||||
const rendererPath = resolveRendererPath();
|
||||
if (rendererPath) {
|
||||
logger.info(`Serving static files from: ${rendererPath}`);
|
||||
// Register static file serving and SPA fallback when renderer output exists.
|
||||
// In dev mode this requires a prior `pnpm build`; in production/standalone it's always present.
|
||||
const rendererPath = resolveRendererPath();
|
||||
if (rendererPath) {
|
||||
logger.info(`Serving static files from: ${rendererPath}`);
|
||||
|
||||
// Cache index.html for SPA fallback
|
||||
const indexHtml = readFileSync(join(rendererPath, 'index.html'), 'utf-8');
|
||||
// Cache index.html for SPA fallback
|
||||
const indexHtml = readFileSync(join(rendererPath, 'index.html'), 'utf-8');
|
||||
|
||||
await this.app.register(fastifyStatic, {
|
||||
root: rendererPath,
|
||||
prefix: '/',
|
||||
wildcard: false,
|
||||
});
|
||||
await this.app.register(fastifyStatic, {
|
||||
root: rendererPath,
|
||||
prefix: '/',
|
||||
wildcard: false,
|
||||
});
|
||||
|
||||
// Register all API routes BEFORE the not-found handler
|
||||
registerHttpRoutes(this.app, services, sshModeSwitchCallback);
|
||||
// Register all API routes BEFORE the not-found handler
|
||||
registerHttpRoutes(this.app, services, sshModeSwitchCallback);
|
||||
|
||||
// SPA fallback: serve index.html for all non-API routes
|
||||
this.app.setNotFoundHandler(async (request, reply) => {
|
||||
if (request.url.startsWith('/api/')) {
|
||||
return reply.status(404).send({ error: 'Not found' });
|
||||
}
|
||||
return reply.type('text/html').send(indexHtml);
|
||||
});
|
||||
} else {
|
||||
logger.warn('Renderer output directory not found, serving API only');
|
||||
registerHttpRoutes(this.app, services, sshModeSwitchCallback);
|
||||
}
|
||||
// SPA fallback: serve index.html for all non-API routes
|
||||
this.app.setNotFoundHandler(async (request, reply) => {
|
||||
if (request.url.startsWith('/api/')) {
|
||||
return reply.status(404).send({ error: 'Not found' });
|
||||
}
|
||||
return reply.type('text/html').send(indexHtml);
|
||||
});
|
||||
} else {
|
||||
// Dev mode: no static serving, just API routes
|
||||
logger.warn('Renderer output directory not found (run `pnpm build` first), serving API only');
|
||||
registerHttpRoutes(this.app, services, sshModeSwitchCallback);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue