@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.
- package/dist/backend/factory.js +16 -5
- package/dist/backend/types.d.ts +7 -3
- package/package.json +1 -1
package/dist/backend/factory.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
171
|
+
mediaUrl: mediaUrlFor(event),
|
|
161
172
|
mountPath,
|
|
162
173
|
frameAncestors,
|
|
163
174
|
setSessionCookie: (token, expiresAt) => {
|
package/dist/backend/types.d.ts
CHANGED
|
@@ -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.
|
|
73
|
-
*
|
|
74
|
-
*
|
|
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
|