@cmssy/astro 9.1.0 → 9.2.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/dist/index.cjs +24 -6
- package/dist/index.js +25 -7
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -11,12 +11,30 @@ function cmssyMiddleware(config, options = {}) {
|
|
|
11
11
|
context.request.headers.delete(core.CMSSY_LOCALE_HEADER);
|
|
12
12
|
const locale = await core.localeForPathname(config, pathname);
|
|
13
13
|
context.request.headers.set(core.CMSSY_LOCALE_HEADER, locale);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const editRequested = context.url.searchParams.getAll(core.CMSSY_EDIT_QUERY_PARAM).includes("1");
|
|
15
|
+
if (editRequested) {
|
|
16
|
+
const verified = await core.isVerifiedEditUrl(context.url, config);
|
|
17
|
+
if (verified && !pathname.startsWith(CMSSY_EDIT_PATH_PREFIX)) {
|
|
18
|
+
context.request.headers.set(core.CMSSY_EDIT_HEADER, "1");
|
|
19
|
+
const target = `${CMSSY_EDIT_PATH_PREFIX}${pathname === "/" ? "" : pathname}${context.url.search}`;
|
|
20
|
+
const response = await context.rewrite(target);
|
|
21
|
+
core.applyCmssyCsp(response, { editorOrigin: config.editorOrigin });
|
|
22
|
+
return response;
|
|
23
|
+
}
|
|
24
|
+
if (!verified && core.isDevelopment()) {
|
|
25
|
+
const { collectEditDiagnostics, renderEditDiagnosticsDocument } = await import('@cmssy/core/preflight');
|
|
26
|
+
const diagnostics = await collectEditDiagnostics({
|
|
27
|
+
config,
|
|
28
|
+
providedSecret: context.url.searchParams.get(
|
|
29
|
+
core.CMSSY_SECRET_QUERY_PARAM
|
|
30
|
+
),
|
|
31
|
+
devOrigin: context.url.origin
|
|
32
|
+
});
|
|
33
|
+
return new Response(renderEditDiagnosticsDocument(diagnostics), {
|
|
34
|
+
status: 200,
|
|
35
|
+
headers: { "content-type": "text/html; charset=utf-8" }
|
|
36
|
+
});
|
|
37
|
+
}
|
|
20
38
|
}
|
|
21
39
|
if (options.stripLocalePrefix && pathname.startsWith(`/${locale}`)) {
|
|
22
40
|
const { defaultLocale } = await core.resolveSiteLocales(config);
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, localeForPathname, isVerifiedEditUrl, applyCmssyCsp, resolveSiteLocales, splitLocaleFromPath, fetchPage, fetchLayouts, fetchPages, normalizeSlug, localizedPath } from '@cmssy/core';
|
|
1
|
+
import { CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, localeForPathname, CMSSY_EDIT_QUERY_PARAM, isVerifiedEditUrl, applyCmssyCsp, isDevelopment, CMSSY_SECRET_QUERY_PARAM, resolveSiteLocales, splitLocaleFromPath, fetchPage, fetchLayouts, fetchPages, normalizeSlug, localizedPath } from '@cmssy/core';
|
|
2
2
|
export { CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, buildBlockContext, createCmssyClient, defineCmssyConfig, fetchLayouts, fetchPage, fetchPageMeta, fetchPages, fetchProduct, fetchProducts, localizeHref, resolveSiteLocales } from '@cmssy/core';
|
|
3
3
|
|
|
4
4
|
// src/middleware.ts
|
|
@@ -10,12 +10,30 @@ function cmssyMiddleware(config, options = {}) {
|
|
|
10
10
|
context.request.headers.delete(CMSSY_LOCALE_HEADER);
|
|
11
11
|
const locale = await localeForPathname(config, pathname);
|
|
12
12
|
context.request.headers.set(CMSSY_LOCALE_HEADER, locale);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const editRequested = context.url.searchParams.getAll(CMSSY_EDIT_QUERY_PARAM).includes("1");
|
|
14
|
+
if (editRequested) {
|
|
15
|
+
const verified = await isVerifiedEditUrl(context.url, config);
|
|
16
|
+
if (verified && !pathname.startsWith(CMSSY_EDIT_PATH_PREFIX)) {
|
|
17
|
+
context.request.headers.set(CMSSY_EDIT_HEADER, "1");
|
|
18
|
+
const target = `${CMSSY_EDIT_PATH_PREFIX}${pathname === "/" ? "" : pathname}${context.url.search}`;
|
|
19
|
+
const response = await context.rewrite(target);
|
|
20
|
+
applyCmssyCsp(response, { editorOrigin: config.editorOrigin });
|
|
21
|
+
return response;
|
|
22
|
+
}
|
|
23
|
+
if (!verified && isDevelopment()) {
|
|
24
|
+
const { collectEditDiagnostics, renderEditDiagnosticsDocument } = await import('@cmssy/core/preflight');
|
|
25
|
+
const diagnostics = await collectEditDiagnostics({
|
|
26
|
+
config,
|
|
27
|
+
providedSecret: context.url.searchParams.get(
|
|
28
|
+
CMSSY_SECRET_QUERY_PARAM
|
|
29
|
+
),
|
|
30
|
+
devOrigin: context.url.origin
|
|
31
|
+
});
|
|
32
|
+
return new Response(renderEditDiagnosticsDocument(diagnostics), {
|
|
33
|
+
status: 200,
|
|
34
|
+
headers: { "content-type": "text/html; charset=utf-8" }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
19
37
|
}
|
|
20
38
|
if (options.stripLocalePrefix && pathname.startsWith(`/${locale}`)) {
|
|
21
39
|
const { defaultLocale } = await resolveSiteLocales(config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/astro",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Astro bindings for cmssy headless sites: middleware, page loader, sitemap and robots.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"vitest": "^2.1.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cmssy/core": "9.
|
|
51
|
+
"@cmssy/core": "9.2.0"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "tsup",
|