@stelstone/server 0.26.2 → 0.26.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stelstone/server",
3
- "version": "0.26.2",
3
+ "version": "0.26.3",
4
4
  "description": "Runtime-agnostic CMS server built on the Web Fetch API, with pluggable adapters for content, media, auth, and build.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/server.mjs CHANGED
@@ -155,20 +155,44 @@ export function startScheduler(content, intervalMs = 60_000) {
155
155
  return () => clearInterval(timer);
156
156
  }
157
157
 
158
+ const PREVIEW_THEME_PATH = "/admin/preview-theme.css";
159
+
160
+ /**
161
+ * The per-site canvas stylesheet.
162
+ *
163
+ * Always answered, even when the site configured none: the admin SPA links it
164
+ * unconditionally, and every mount ends in an SPA fallback that would hand the
165
+ * browser index.html labelled as CSS.
166
+ */
167
+ function previewThemeResponse(previewThemeCss) {
168
+ if (previewThemeCss && fs.existsSync(previewThemeCss)) {
169
+ return fileResponse(path.resolve(previewThemeCss));
170
+ }
171
+ return new Response("/* no preview-theme.css configured */", {
172
+ headers: { "Content-Type": "text/css" },
173
+ });
174
+ }
175
+
176
+ /**
177
+ * Connect middleware that answers the preview stylesheet and passes everything
178
+ * else along. Used by the Vite mount, whose own SPA fallback would otherwise
179
+ * swallow the path.
180
+ */
181
+ export function createPreviewThemeMiddleware(previewThemeCss) {
182
+ return toNodeMiddleware(async (request) =>
183
+ new URL(request.url).pathname === PREVIEW_THEME_PATH
184
+ ? previewThemeResponse(previewThemeCss)
185
+ : null,
186
+ );
187
+ }
188
+
158
189
  /** Serve the prebuilt admin SPA, plus the optional per-site preview stylesheet. */
159
190
  function createAdminUiHandler({ dir, previewThemeCss }) {
160
191
  const files = createStaticHandler({ root: dir, mount: "/admin", spaFallback: true });
161
192
  return function serveAdminUi(request) {
162
193
  const { pathname } = new URL(request.url);
163
194
  // Answer before the static handler so the <link> never 404s.
164
- if (pathname === "/admin/preview-theme.css") {
165
- if (previewThemeCss && fs.existsSync(previewThemeCss)) {
166
- return fileResponse(path.resolve(previewThemeCss));
167
- }
168
- return new Response("/* no preview-theme.css configured */", {
169
- headers: { "Content-Type": "text/css" },
170
- });
171
- }
195
+ if (pathname === PREVIEW_THEME_PATH) return previewThemeResponse(previewThemeCss);
172
196
  return files(request);
173
197
  };
174
198
  }
@@ -258,8 +282,18 @@ export async function resolveAdminUi(adminUi) {
258
282
  appType: "spa",
259
283
  });
260
284
  console.log("Admin UI: Vite dev middleware (HMR enabled)");
285
+
286
+ // Vite owns /admin here, and its SPA fallback answers every unmatched path
287
+ // with index.html — so the preview stylesheet arrived as HTML and the
288
+ // browser dropped it, leaving the canvas unstyled whenever the admin UI
289
+ // ran from source. Only the static mount used to answer this path; now
290
+ // both do, and `previewThemeCss` means the same thing in dev and in prod.
291
+ const viteMiddleware = mountPrefix("/admin", vite.middlewares);
292
+ const previewTheme = createPreviewThemeMiddleware(resolved.previewThemeCss);
293
+
261
294
  return {
262
- nodeMiddleware: mountPrefix("/admin", vite.middlewares),
295
+ nodeMiddleware: (req, res, next) =>
296
+ previewTheme(req, res, () => viteMiddleware(req, res, next)),
263
297
  previewThemeCss: resolved.previewThemeCss,
264
298
  };
265
299
  }
package/src/version.mjs CHANGED
@@ -5,4 +5,4 @@
5
5
  * require() and no import.meta.url, so reading the manifest at runtime yields
6
6
  * "unknown" there.
7
7
  */
8
- export const SERVER_VERSION = "0.26.2";
8
+ export const SERVER_VERSION = "0.26.3";