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:watch": "vitest",
|
||||||
"test:coverage": "vitest run --coverage",
|
"test:coverage": "vitest run --coverage",
|
||||||
"test:coverage:critical": "vitest run --coverage --config vitest.critical.config.ts",
|
"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": "tsx src/main/standalone.ts",
|
||||||
"standalone:build": "electron-vite build && vite build --config vite.standalone.config.ts",
|
"standalone:build": "electron-vite build && vite build --config vite.standalone.config.ts",
|
||||||
"standalone:start": "node dist-standalone/index.cjs"
|
"standalone:start": "node dist-standalone/index.cjs"
|
||||||
|
|
@ -56,7 +53,6 @@
|
||||||
"@dnd-kit/utilities": "^3.2.2",
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
"@fastify/cors": "^11.2.0",
|
"@fastify/cors": "^11.2.0",
|
||||||
"@fastify/static": "^9.0.0",
|
"@fastify/static": "^9.0.0",
|
||||||
"@remotion/light-leaks": "4.0.421",
|
|
||||||
"@tanstack/react-virtual": "^3.10.8",
|
"@tanstack/react-virtual": "^3.10.8",
|
||||||
"date-fns": "^3.6.0",
|
"date-fns": "^3.6.0",
|
||||||
"electron-updater": "^6.7.3",
|
"electron-updater": "^6.7.3",
|
||||||
|
|
@ -133,6 +129,9 @@
|
||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"asar": true,
|
"asar": true,
|
||||||
|
"asarUnpack": [
|
||||||
|
"out/renderer/**"
|
||||||
|
],
|
||||||
"npmRebuild": false,
|
"npmRebuild": false,
|
||||||
"extraMetadata": {
|
"extraMetadata": {
|
||||||
"main": "dist-electron/main/index.cjs"
|
"main": "dist-electron/main/index.cjs"
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,13 @@ const logger = createLogger('Service:HttpServer');
|
||||||
*/
|
*/
|
||||||
function resolveRendererPath(): string | null {
|
function resolveRendererPath(): string | null {
|
||||||
const candidates = [
|
const candidates = [
|
||||||
// Electron production paths
|
// Electron production (asarUnpack): app.asar.unpacked/out/renderer (real filesystem)
|
||||||
join(__dirname, '../../../out/renderer'),
|
join(__dirname, '../../out/renderer').replace('app.asar', 'app.asar.unpacked'),
|
||||||
join(__dirname, '../../renderer'),
|
// Electron production (asar fallback): app.asar/out/renderer
|
||||||
|
join(__dirname, '../../out/renderer'),
|
||||||
// Standalone: dist-standalone/index.cjs → ../out/renderer
|
// Standalone: dist-standalone/index.cjs → ../out/renderer
|
||||||
join(__dirname, '../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'),
|
join(process.cwd(), 'out/renderer'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -89,38 +90,33 @@ export class HttpServer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register static file serving and SPA fallback (production only)
|
// Register static file serving and SPA fallback when renderer output exists.
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
// In dev mode this requires a prior `pnpm build`; in production/standalone it's always present.
|
||||||
if (!isDev) {
|
const rendererPath = resolveRendererPath();
|
||||||
const rendererPath = resolveRendererPath();
|
if (rendererPath) {
|
||||||
if (rendererPath) {
|
logger.info(`Serving static files from: ${rendererPath}`);
|
||||||
logger.info(`Serving static files from: ${rendererPath}`);
|
|
||||||
|
|
||||||
// Cache index.html for SPA fallback
|
// Cache index.html for SPA fallback
|
||||||
const indexHtml = readFileSync(join(rendererPath, 'index.html'), 'utf-8');
|
const indexHtml = readFileSync(join(rendererPath, 'index.html'), 'utf-8');
|
||||||
|
|
||||||
await this.app.register(fastifyStatic, {
|
await this.app.register(fastifyStatic, {
|
||||||
root: rendererPath,
|
root: rendererPath,
|
||||||
prefix: '/',
|
prefix: '/',
|
||||||
wildcard: false,
|
wildcard: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register all API routes BEFORE the not-found handler
|
// Register all API routes BEFORE the not-found handler
|
||||||
registerHttpRoutes(this.app, services, sshModeSwitchCallback);
|
registerHttpRoutes(this.app, services, sshModeSwitchCallback);
|
||||||
|
|
||||||
// SPA fallback: serve index.html for all non-API routes
|
// SPA fallback: serve index.html for all non-API routes
|
||||||
this.app.setNotFoundHandler(async (request, reply) => {
|
this.app.setNotFoundHandler(async (request, reply) => {
|
||||||
if (request.url.startsWith('/api/')) {
|
if (request.url.startsWith('/api/')) {
|
||||||
return reply.status(404).send({ error: 'Not found' });
|
return reply.status(404).send({ error: 'Not found' });
|
||||||
}
|
}
|
||||||
return reply.type('text/html').send(indexHtml);
|
return reply.type('text/html').send(indexHtml);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
logger.warn('Renderer output directory not found, serving API only');
|
|
||||||
registerHttpRoutes(this.app, services, sshModeSwitchCallback);
|
|
||||||
}
|
|
||||||
} else {
|
} 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);
|
registerHttpRoutes(this.app, services, sshModeSwitchCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue