@natilon/cms-server 0.5.0 → 0.8.0
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 +2 -2
- package/src/adapters/basic-auth.mjs +7 -2
- package/src/routes.mjs +29 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@natilon/cms-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Express-based CMS server with pluggable adapters for content, media, auth, and build.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"bin"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@natilon/admin-ui": "
|
|
38
|
+
"@natilon/admin-ui": ">=0.5.0",
|
|
39
39
|
"express": "^4.21.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -27,9 +27,14 @@ export function createBasicAuth({
|
|
|
27
27
|
realm = "Admin",
|
|
28
28
|
}) {
|
|
29
29
|
// Normalise: prefer `users` array, fall back to single user/pass pair.
|
|
30
|
-
|
|
30
|
+
// Each entry may use `pass` (plaintext) or `passEnv` (env var name).
|
|
31
|
+
const userList = (users?.length
|
|
31
32
|
? users
|
|
32
|
-
: pass ? [{ user: user || "admin", pass, role: "admin" }] : []
|
|
33
|
+
: pass ? [{ user: user || "admin", pass, role: "admin" }] : []
|
|
34
|
+
).map((entry) => ({
|
|
35
|
+
...entry,
|
|
36
|
+
pass: entry.passEnv ? process.env[entry.passEnv] : entry.pass,
|
|
37
|
+
}));
|
|
33
38
|
|
|
34
39
|
const configured = userList.length > 0;
|
|
35
40
|
|
package/src/routes.mjs
CHANGED
|
@@ -170,6 +170,35 @@ export const apiRoutes = [
|
|
|
170
170
|
},
|
|
171
171
|
},
|
|
172
172
|
|
|
173
|
+
// ── Preview URL ────────────────────────────────────────────────────────
|
|
174
|
+
// Resolves the preview URL for an entry. Supports both `config.previewUrl`
|
|
175
|
+
// (a function, called server-side with the page data) and the simpler
|
|
176
|
+
// `config.previewUrlPattern` (template string with {collection}/{slug}/{lang}).
|
|
177
|
+
{
|
|
178
|
+
method: "GET",
|
|
179
|
+
path: "/api/preview-url/:collection/:file",
|
|
180
|
+
auth: "any",
|
|
181
|
+
handler: async ({ adapters, params, config }) => {
|
|
182
|
+
const data = await adapters.content.readPage(params.collection, params.file);
|
|
183
|
+
if (!data) return notFound();
|
|
184
|
+
|
|
185
|
+
let url = null;
|
|
186
|
+
if (typeof config.previewUrl === "function") {
|
|
187
|
+
try {
|
|
188
|
+
url = config.previewUrl({ collection: params.collection, data });
|
|
189
|
+
} catch (err) {
|
|
190
|
+
return { status: 500, json: { error: `previewUrl(): ${err.message}` } };
|
|
191
|
+
}
|
|
192
|
+
} else if (config.previewUrlPattern) {
|
|
193
|
+
url = config.previewUrlPattern
|
|
194
|
+
.replace("{collection}", data.collection || params.collection)
|
|
195
|
+
.replace("{slug}", data.slug || "")
|
|
196
|
+
.replace("{lang}", data.lang || "");
|
|
197
|
+
}
|
|
198
|
+
return ok({ url });
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
|
|
173
202
|
// ── History ────────────────────────────────────────────────────────────
|
|
174
203
|
{
|
|
175
204
|
method: "GET",
|