Skip to content

Commit 81b88da

Browse files
authored
Merge pull request #57 from openai/katia/live-updates
Update build process to serve assets that hot-reload
2 parents a272999 + cf88017 commit 81b88da

File tree

5 files changed

+246
-207
lines changed

5 files changed

+246
-207
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pnpm run build
5454

5555
This command runs `build-all.mts`, producing versioned `.html`, `.js`, and `.css` files inside `assets/`. Each widget is wrapped with the CSS it needs so you can host the bundles directly or ship them with your own server.
5656

57-
To iterate locally, you can also launch the Vite dev server:
57+
To iterate on your components locally, you can also launch the Vite dev server:
5858

5959
```bash
6060
pnpm run dev
@@ -130,12 +130,23 @@ You can add your app to the conversation context by selecting it in the "More" o
130130

131131
You can then invoke tools by asking something related. For example, for the Pizzaz app, you can ask "What are the best pizzas in town?".
132132

133-
134133
## Next steps
135134

136135
- Customize the widget data: edit the handlers in `pizzaz_server_node/src`, `pizzaz_server_python/main.py`, or the solar system server to fetch data from your systems.
137136
- Create your own components and add them to the gallery: drop new entries into `src/` and they will be picked up automatically by the build script.
138137

138+
### Deploy your MCP server
139+
140+
You can use the cloud environment of your choice to deploy your MCP server.
141+
142+
Include this in the environment variables:
143+
144+
```
145+
BASE_URL=https://your-server.com
146+
```
147+
148+
This will be used to generate the HTML for the widgets so that they can serve static assets from this hosted url.
149+
139150
## Contributing
140151

141152
You are welcome to open issues or submit PRs to improve this app, however, please note that we may not review all suggestions.

build-all.mts

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const targets: string[] = [
2121
"pizzaz-carousel",
2222
"pizzaz-list",
2323
"pizzaz-albums",
24-
"pizzaz-video",
2524
];
2625
const builtNames: string[] = [];
2726

@@ -143,8 +142,6 @@ const outputs = fs
143142
.map((f) => path.join("assets", f))
144143
.filter((p) => fs.existsSync(p));
145144

146-
const renamed = [];
147-
148145
const h = crypto
149146
.createHash("sha256")
150147
.update(pkg.version, "utf8")
@@ -159,38 +156,35 @@ for (const out of outputs) {
159156
const newName = path.join(dir, `${base}-${h}${ext}`);
160157

161158
fs.renameSync(out, newName);
162-
renamed.push({ old: out, neu: newName });
163159
console.log(`${out} -> ${newName}`);
164160
}
165161
console.groupEnd();
166162

167163
console.log("new hash: ", h);
168164

165+
const defaultBaseUrl = "http://localhost:4444";
166+
const baseUrlCandidate = process.env.BASE_URL?.trim() ?? "";
167+
const baseUrlRaw = baseUrlCandidate.length > 0 ? baseUrlCandidate : defaultBaseUrl;
168+
const normalizedBaseUrl = baseUrlRaw.replace(/\/+$/, "") || defaultBaseUrl;
169+
console.log(`Using BASE_URL ${normalizedBaseUrl} for generated HTML`);
170+
169171
for (const name of builtNames) {
170172
const dir = outDir;
171-
const htmlPath = path.join(dir, `${name}-${h}.html`);
172-
const cssPath = path.join(dir, `${name}-${h}.css`);
173-
const jsPath = path.join(dir, `${name}-${h}.js`);
174-
175-
const css = fs.existsSync(cssPath)
176-
? fs.readFileSync(cssPath, { encoding: "utf8" })
177-
: "";
178-
const js = fs.existsSync(jsPath)
179-
? fs.readFileSync(jsPath, { encoding: "utf8" })
180-
: "";
181-
182-
const cssBlock = css ? `\n <style>\n${css}\n </style>\n` : "";
183-
const jsBlock = js ? `\n <script type="module">\n${js}\n </script>` : "";
184-
185-
const html = [
186-
"<!doctype html>",
187-
"<html>",
188-
`<head>${cssBlock}</head>`,
189-
"<body>",
190-
` <div id="${name}-root"></div>${jsBlock}`,
191-
"</body>",
192-
"</html>",
193-
].join("\n");
194-
fs.writeFileSync(htmlPath, html, { encoding: "utf8" });
195-
console.log(`${htmlPath} (generated)`);
173+
const hashedHtmlPath = path.join(dir, `${name}-${h}.html`);
174+
const liveHtmlPath = path.join(dir, `${name}.html`);
175+
const html = `<!doctype html>
176+
<html>
177+
<head>
178+
<script type="module" src="${normalizedBaseUrl}/${name}.js"></script>
179+
<link rel="stylesheet" href="${normalizedBaseUrl}/${name}.css">
180+
</head>
181+
<body>
182+
<div id="${name}-root"></div>
183+
</body>
184+
</html>
185+
`;
186+
fs.writeFileSync(hashedHtmlPath, html, { encoding: "utf8" });
187+
fs.writeFileSync(liveHtmlPath, html, { encoding: "utf8" });
188+
console.log(`${hashedHtmlPath} (generated live HTML)`);
189+
console.log(`${liveHtmlPath} (generated live HTML)`);
196190
}

0 commit comments

Comments
 (0)