mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-01 19:42:03 +00:00
fix(studio): serve runtime locally instead of from CDN
The Vite dev server was loading the HyperFrames runtime IIFE from cdn.jsdelivr.net. This caused compositions using window.__hyperframes (e.g., fitTextFontSize) to fail when the CDN script didn't load in the iframe context. Add a /api/runtime.js endpoint to the Vite plugin that serves the local built runtime, matching what studioServer.ts already does for the CLI embedded server. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
6956531ecc
commit
45996c3523
@@ -146,7 +146,7 @@ function createViteAdapter(dataDir: string, server: ViteDevServer): StudioApiAda
|
||||
return mod.lintHyperframeHtml(html, opts);
|
||||
},
|
||||
|
||||
runtimeUrl: "https://cdn.jsdelivr.net/npm/@hyperframes/core/dist/hyperframe.runtime.iife.js",
|
||||
runtimeUrl: "/api/runtime.js",
|
||||
|
||||
rendersDir: () => resolve(dataDir, "../renders"),
|
||||
|
||||
@@ -363,6 +363,22 @@ function devProjectApi(): Plugin {
|
||||
return _api;
|
||||
};
|
||||
|
||||
// Serve the local runtime IIFE so compositions don't depend on CDN
|
||||
const runtimePath = resolve(__dirname, "../core/dist/hyperframe.runtime.iife.js");
|
||||
server.middlewares.use((req, res, next) => {
|
||||
if (req.url !== "/api/runtime.js") return next();
|
||||
if (!existsSync(runtimePath)) {
|
||||
res.writeHead(404);
|
||||
res.end("runtime not built — run pnpm build in packages/core");
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, {
|
||||
"Content-Type": "text/javascript",
|
||||
"Cache-Control": "no-store",
|
||||
});
|
||||
res.end(readFileSync(runtimePath, "utf-8"));
|
||||
});
|
||||
|
||||
server.middlewares.use(async (req, res, next) => {
|
||||
if (!req.url?.startsWith("/api/")) return next();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user