@velastack/cms 0.2.0 → 0.2.1

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.
@@ -55,11 +55,22 @@ export const createCmsBackend = (options = {}) => {
55
55
  const suffix = `/${restPath}`;
56
56
  return pathname.endsWith(suffix) ? pathname.slice(0, -suffix.length) : pathname;
57
57
  };
58
- const mediaUrlFor = (event, mountPath) => {
58
+ /**
59
+ * The base for URLs written into `media_items.url` and embedded in content.
60
+ *
61
+ * Root-relative by default, and deliberately so: content outlives the origin
62
+ * it was authored on. An absolute default would bake `http://localhost:5173`
63
+ * into every image a developer added before deploying, and those URLs would
64
+ * still point at localhost in production. A root-relative `/uploads/<file>`
65
+ * resolves correctly wherever the site is served, and the client resolves it
66
+ * against the CMS endpoint when the two are on different origins.
67
+ *
68
+ * A cross-origin deployment — where the CMS and the site are genuinely
69
+ * different hosts — passes an absolute `mediaBaseUrl` explicitly.
70
+ */
71
+ const mediaUrlFor = (event) => {
59
72
  const base = options.mediaBaseUrl;
60
- const resolved = typeof base === 'function'
61
- ? base(event)
62
- : (base ?? `${new URL(mountPath, event.url).origin}/uploads`);
73
+ const resolved = typeof base === 'function' ? base(event) : (base ?? '/uploads');
63
74
  const trimmed = resolved.replace(/\/$/, '');
64
75
  return (filename) => `${trimmed}/${filename}`;
65
76
  };
@@ -157,7 +168,7 @@ export const createCmsBackend = (options = {}) => {
157
168
  storage,
158
169
  auth,
159
170
  authCtx,
160
- mediaUrl: mediaUrlFor(event, mountPath),
171
+ mediaUrl: mediaUrlFor(event),
161
172
  mountPath,
162
173
  frameAncestors,
163
174
  setSessionCookie: (token, expiresAt) => {
@@ -69,9 +69,13 @@ export type CmsBackendOptions = {
69
69
  uploadDir?: string;
70
70
  /**
71
71
  * Base URL for media, written into `media_items.url` and embedded in
72
- * content. Defaults to a root-relative `/uploads`, which keeps the origin
73
- * out of stored content. Pass an absolute base when the CMS is on a
74
- * different origin than the site or to preserve an existing wire format.
72
+ * content.
73
+ *
74
+ * Defaults to a root-relative `/uploads`, which keeps the origin out of
75
+ * stored content — an absolute default would bake the authoring origin
76
+ * (`http://localhost:5173`) into every image added before deploy. Pass an
77
+ * absolute base when the CMS is served from a different origin than the
78
+ * site, or to preserve an existing wire format.
75
79
  */
76
80
  mediaBaseUrl?: string | ((event: RequestEvent) => string);
77
81
  /** Which tenant this request is for. Returning `null` is a 404. Defaults to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velastack/cms",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A scope-aware CMS for SvelteKit, for static or dynamic sites.",
5
5
  "keywords": [
6
6
  "svelte",