@flexacms/nuxt 0.3.0 → 0.3.2
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/README.md
CHANGED
|
@@ -15,7 +15,7 @@ export default defineNuxtConfig({
|
|
|
15
15
|
|
|
16
16
|
```env
|
|
17
17
|
NUXT_FLEXA_API_KEY=flx_...
|
|
18
|
-
# NUXT_FLEXA_URL=https://staging.example.com # optional, defaults to https://flexacms.com
|
|
18
|
+
# NUXT_FLEXA_URL=https://staging.example.com # optional, defaults to https://app.flexacms.com
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
```vue
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
// src/runtime/proxy-path.ts
|
|
2
|
-
var ALLOWED_QUERY = [
|
|
3
|
-
"status",
|
|
4
|
-
"search",
|
|
5
|
-
"category",
|
|
6
|
-
"page",
|
|
7
|
-
"per_page"
|
|
8
|
-
];
|
|
2
|
+
var ALLOWED_QUERY = ["search", "category", "page", "per_page"];
|
|
9
3
|
function proxyRequestPath(path, query) {
|
|
10
4
|
const segments = path.split("/").filter(Boolean);
|
|
11
5
|
if (segments.length === 0 || segments.length > 2 || segments.some((segment) => segment === ".." || segment === ".")) {
|
|
@@ -15,6 +9,9 @@ function proxyRequestPath(path, query) {
|
|
|
15
9
|
return null;
|
|
16
10
|
}
|
|
17
11
|
const search = new URLSearchParams();
|
|
12
|
+
if (segments.length === 1 && segments[0] !== "entities") {
|
|
13
|
+
search.set("status", "published");
|
|
14
|
+
}
|
|
18
15
|
for (const key of ALLOWED_QUERY) {
|
|
19
16
|
const value = query[key];
|
|
20
17
|
if (typeof value === "string" || typeof value === "number") {
|
|
@@ -27,7 +24,12 @@ function proxyRequestPath(path, query) {
|
|
|
27
24
|
const queryString = search.toString();
|
|
28
25
|
return `/${segments.map(encodeURIComponent).join("/")}${queryString ? `?${queryString}` : ""}`;
|
|
29
26
|
}
|
|
27
|
+
function isEntryPath(path) {
|
|
28
|
+
const segments = (path.split("?")[0] ?? "").split("/").filter(Boolean);
|
|
29
|
+
return segments.length === 2 && segments[0] !== "entities" && segments[1] !== "schema";
|
|
30
|
+
}
|
|
30
31
|
|
|
31
32
|
export {
|
|
32
|
-
proxyRequestPath
|
|
33
|
+
proxyRequestPath,
|
|
34
|
+
isEntryPath
|
|
33
35
|
};
|
package/dist/module.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ interface FlexaRegister {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
interface ModuleOptions {
|
|
20
|
-
/** Flexa URL. Defaults to https://flexacms.com. Prefer the NUXT_FLEXA_URL environment variable. */
|
|
20
|
+
/** Flexa URL. Defaults to https://app.flexacms.com. Prefer the NUXT_FLEXA_URL environment variable. */
|
|
21
21
|
url?: string;
|
|
22
22
|
/** API key, kept server-side. Prefer the NUXT_FLEXA_API_KEY environment variable. */
|
|
23
23
|
apiKey?: string;
|
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
useFlexaClient
|
|
3
3
|
} from "../../chunk-XTVVLL44.js";
|
|
4
4
|
import {
|
|
5
|
+
isEntryPath,
|
|
5
6
|
proxyRequestPath
|
|
6
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-3HLT7X6R.js";
|
|
7
8
|
|
|
8
9
|
// src/runtime/server/proxy.ts
|
|
9
10
|
import { isFlexaError } from "@flexacms/client";
|
|
@@ -17,7 +18,11 @@ var proxy_default = defineEventHandler(async (event) => {
|
|
|
17
18
|
throw createError({ statusCode: 404, statusMessage: "Not Found" });
|
|
18
19
|
}
|
|
19
20
|
try {
|
|
20
|
-
|
|
21
|
+
const result = await useFlexaClient().request("GET", path);
|
|
22
|
+
if (isEntryPath(path) && result?.data?.status !== "published") {
|
|
23
|
+
throw createError({ statusCode: 404, statusMessage: "Not Found" });
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
21
26
|
} catch (error) {
|
|
22
27
|
if (isFlexaError(error)) {
|
|
23
28
|
throw createError({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexacms/nuxt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Nuxt module for the Flexa headless CMS: auto-imported composables and a read-only server proxy that keeps your API key private.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"typecheck": "tsc -p tsconfig.json"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@flexacms/client": "^0.3.
|
|
45
|
+
"@flexacms/client": "^0.3.2",
|
|
46
46
|
"@nuxt/kit": "^3.12.0 || ^4.0.0",
|
|
47
47
|
"defu": "^6.1.4"
|
|
48
48
|
},
|