@conloca/cloud-astro 0.2.2 → 0.2.4
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 +378 -207
- package/dist/.build-inputs.json +69 -0
- package/dist/src/component-manifest.d.ts +5 -3
- package/dist/src/component-manifest.d.ts.map +1 -1
- package/dist/src/component-manifest.js +7 -7
- package/dist/src/component-manifest.js.map +1 -1
- package/dist/src/constants.d.ts +14 -13
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +14 -13
- package/dist/src/constants.js.map +1 -1
- package/dist/src/d3-build.d.ts +70 -0
- package/dist/src/d3-build.d.ts.map +1 -0
- package/dist/src/d3-build.js +272 -0
- package/dist/src/d3-build.js.map +1 -0
- package/dist/src/descriptors.d.ts +2 -2
- package/dist/src/descriptors.d.ts.map +1 -1
- package/dist/src/descriptors.js +4 -2
- package/dist/src/descriptors.js.map +1 -1
- package/dist/src/doctor/checks-address.d.ts +18 -0
- package/dist/src/doctor/checks-address.d.ts.map +1 -0
- package/dist/src/doctor/checks-address.js +163 -0
- package/dist/src/doctor/checks-address.js.map +1 -0
- package/dist/src/doctor/checks-live.d.ts +8 -5
- package/dist/src/doctor/checks-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-live.js +226 -188
- package/dist/src/doctor/checks-live.js.map +1 -1
- package/dist/src/doctor/checks-offline.d.ts +6 -25
- package/dist/src/doctor/checks-offline.d.ts.map +1 -1
- package/dist/src/doctor/checks-offline.js +30 -259
- package/dist/src/doctor/checks-offline.js.map +1 -1
- package/dist/src/doctor/checks-preview-limits.d.ts +11 -0
- package/dist/src/doctor/checks-preview-limits.d.ts.map +1 -0
- package/dist/src/doctor/checks-preview-limits.js +133 -0
- package/dist/src/doctor/checks-preview-limits.js.map +1 -0
- package/dist/src/doctor/checks-preview-live.d.ts +14 -0
- package/dist/src/doctor/checks-preview-live.d.ts.map +1 -0
- package/dist/src/doctor/checks-preview-live.js +72 -0
- package/dist/src/doctor/checks-preview-live.js.map +1 -0
- package/dist/src/doctor/checks-preview.d.ts +7 -0
- package/dist/src/doctor/checks-preview.d.ts.map +1 -0
- package/dist/src/doctor/checks-preview.js +287 -0
- package/dist/src/doctor/checks-preview.js.map +1 -0
- package/dist/src/doctor/config-scan.d.ts +12 -3
- package/dist/src/doctor/config-scan.d.ts.map +1 -1
- package/dist/src/doctor/config-scan.js +38 -11
- package/dist/src/doctor/config-scan.js.map +1 -1
- package/dist/src/doctor/run.d.ts.map +1 -1
- package/dist/src/doctor/run.js +16 -10
- package/dist/src/doctor/run.js.map +1 -1
- package/dist/src/doctor/types.d.ts +17 -7
- package/dist/src/doctor/types.d.ts.map +1 -1
- package/dist/src/doctor/types.js +17 -7
- package/dist/src/doctor/types.js.map +1 -1
- package/dist/src/editor-page/bundle.d.ts +90 -0
- package/dist/src/editor-page/bundle.d.ts.map +1 -0
- package/dist/src/editor-page/bundle.js +373 -0
- package/dist/src/editor-page/bundle.js.map +1 -0
- package/dist/src/editor-page/data-schemas.d.ts +16 -0
- package/dist/src/editor-page/data-schemas.d.ts.map +1 -0
- package/dist/src/editor-page/data-schemas.js +39 -0
- package/dist/src/editor-page/data-schemas.js.map +1 -0
- package/dist/src/editor-page/emit.d.ts +69 -0
- package/dist/src/editor-page/emit.d.ts.map +1 -0
- package/dist/src/editor-page/emit.js +254 -0
- package/dist/src/editor-page/emit.js.map +1 -0
- package/dist/src/editor-page/framing.d.ts +23 -0
- package/dist/src/editor-page/framing.d.ts.map +1 -0
- package/dist/src/editor-page/framing.js +39 -0
- package/dist/src/editor-page/framing.js.map +1 -0
- package/dist/src/editor-page/page.d.ts +9 -0
- package/dist/src/editor-page/page.d.ts.map +1 -0
- package/dist/src/editor-page/page.js +31 -0
- package/dist/src/editor-page/page.js.map +1 -0
- package/dist/src/editor-page/site-base.d.ts +4 -0
- package/dist/src/editor-page/site-base.d.ts.map +1 -0
- package/dist/src/editor-page/site-base.js +13 -0
- package/dist/src/editor-page/site-base.js.map +1 -0
- package/dist/src/git.d.ts +11 -8
- package/dist/src/git.d.ts.map +1 -1
- package/dist/src/git.js +25 -8
- package/dist/src/git.js.map +1 -1
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +11 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/integration.d.ts +1 -1
- package/dist/src/integration.d.ts.map +1 -1
- package/dist/src/integration.js +377 -416
- package/dist/src/integration.js.map +1 -1
- package/dist/src/node.d.ts +3 -1
- package/dist/src/node.d.ts.map +1 -1
- package/dist/src/node.js +7 -2
- package/dist/src/node.js.map +1 -1
- package/dist/src/preview/_dispatch.d.ts +12 -0
- package/dist/src/preview/_dispatch.d.ts.map +1 -1
- package/dist/src/preview/_dispatch.js +31 -0
- package/dist/src/preview/_dispatch.js.map +1 -1
- package/dist/src/preview/_resolve-opts.d.ts +19 -10
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
- package/dist/src/preview/_resolve-opts.js +24 -11
- package/dist/src/preview/_resolve-opts.js.map +1 -1
- package/dist/src/preview/banner.d.ts +12 -9
- package/dist/src/preview/banner.d.ts.map +1 -1
- package/dist/src/preview/banner.js +46 -43
- package/dist/src/preview/banner.js.map +1 -1
- package/dist/src/preview/cloudflare-adapter.d.ts +35 -0
- package/dist/src/preview/cloudflare-adapter.d.ts.map +1 -0
- package/dist/src/preview/cloudflare-adapter.js +92 -0
- package/dist/src/preview/cloudflare-adapter.js.map +1 -0
- package/dist/src/preview/cookie.d.ts +13 -14
- package/dist/src/preview/cookie.d.ts.map +1 -1
- package/dist/src/preview/cookie.js +19 -26
- package/dist/src/preview/cookie.js.map +1 -1
- package/dist/src/preview/dispatcher.d.ts +73 -0
- package/dist/src/preview/dispatcher.d.ts.map +1 -0
- package/dist/src/preview/dispatcher.js +329 -0
- package/dist/src/preview/dispatcher.js.map +1 -0
- package/dist/src/preview/entry-code.d.ts +33 -0
- package/dist/src/preview/entry-code.d.ts.map +1 -0
- package/dist/src/preview/entry-code.js +33 -0
- package/dist/src/preview/entry-code.js.map +1 -0
- package/dist/src/preview/headers.d.ts +24 -4
- package/dist/src/preview/headers.d.ts.map +1 -1
- package/dist/src/preview/headers.js +35 -7
- package/dist/src/preview/headers.js.map +1 -1
- package/dist/src/preview/label.d.ts +8 -0
- package/dist/src/preview/label.d.ts.map +1 -0
- package/dist/src/preview/label.js +14 -0
- package/dist/src/preview/label.js.map +1 -0
- package/dist/src/preview/landing.d.ts +23 -2
- package/dist/src/preview/landing.d.ts.map +1 -1
- package/dist/src/preview/landing.js +105 -37
- package/dist/src/preview/landing.js.map +1 -1
- package/dist/src/preview/middleware.d.ts +49 -22
- package/dist/src/preview/middleware.d.ts.map +1 -1
- package/dist/src/preview/middleware.js +259 -100
- package/dist/src/preview/middleware.js.map +1 -1
- package/dist/src/preview/preview-path.d.ts +47 -5
- package/dist/src/preview/preview-path.d.ts.map +1 -1
- package/dist/src/preview/preview-path.js +65 -8
- package/dist/src/preview/preview-path.js.map +1 -1
- package/dist/src/preview/redeem-url.d.ts +7 -0
- package/dist/src/preview/redeem-url.d.ts.map +1 -0
- package/dist/src/preview/redeem-url.js +14 -0
- package/dist/src/preview/redeem-url.js.map +1 -0
- package/dist/src/preview/site-middleware.d.ts +5 -5
- package/dist/src/preview/site-middleware.d.ts.map +1 -1
- package/dist/src/preview/site-middleware.js +53 -26
- package/dist/src/preview/site-middleware.js.map +1 -1
- package/dist/src/preview-build.d.ts +29 -15
- package/dist/src/preview-build.d.ts.map +1 -1
- package/dist/src/preview-build.js +66 -25
- package/dist/src/preview-build.js.map +1 -1
- package/dist/src/preview.d.ts +1 -1
- package/dist/src/preview.d.ts.map +1 -1
- package/dist/src/preview.js +1 -1
- package/dist/src/preview.js.map +1 -1
- package/dist/src/repository.d.ts +1 -1
- package/dist/src/repository.js +1 -1
- package/dist/src/resolve-options.d.ts +17 -0
- package/dist/src/resolve-options.d.ts.map +1 -0
- package/dist/src/resolve-options.js +21 -0
- package/dist/src/resolve-options.js.map +1 -0
- package/dist/src/site-id.d.ts +0 -2
- package/dist/src/site-id.d.ts.map +1 -1
- package/dist/src/site-id.js +2 -3
- package/dist/src/site-id.js.map +1 -1
- package/dist/src/skill.d.ts +11 -0
- package/dist/src/skill.d.ts.map +1 -1
- package/dist/src/skill.js +32 -9
- package/dist/src/skill.js.map +1 -1
- package/dist/src/types.d.ts +33 -78
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +63 -13
- package/src/component-manifest.ts +11 -8
- package/src/constants.ts +15 -13
- package/src/d3-build.ts +315 -0
- package/src/descriptors.ts +6 -4
- package/src/doctor/checks-address.ts +190 -0
- package/src/doctor/checks-live.ts +262 -268
- package/src/doctor/checks-offline.ts +32 -279
- package/src/doctor/checks-preview-limits.ts +137 -0
- package/src/doctor/checks-preview-live.ts +77 -0
- package/src/doctor/checks-preview.ts +302 -0
- package/src/doctor/config-scan.ts +35 -9
- package/src/doctor/run.ts +18 -16
- package/src/doctor/types.ts +17 -7
- package/src/editor-page/bundle.ts +487 -0
- package/src/editor-page/data-schemas.ts +47 -0
- package/src/editor-page/emit.ts +362 -0
- package/src/editor-page/framing.ts +62 -0
- package/src/editor-page/page.ts +37 -0
- package/src/editor-page/site-base.ts +11 -0
- package/src/git.ts +29 -10
- package/src/index.ts +22 -6
- package/src/integration.ts +399 -469
- package/src/node.ts +18 -2
- package/src/preview/_dispatch.ts +36 -1
- package/src/preview/_resolve-opts.ts +35 -12
- package/src/preview/banner.ts +61 -43
- package/src/preview/cloudflare-adapter.ts +103 -0
- package/src/preview/cookie.ts +18 -24
- package/src/preview/dispatcher.ts +407 -0
- package/src/preview/entry-code.ts +51 -0
- package/src/preview/headers.ts +35 -7
- package/src/preview/label.ts +12 -0
- package/src/preview/landing.ts +117 -39
- package/src/preview/middleware.ts +302 -115
- package/src/preview/preview-path.ts +83 -8
- package/src/preview/redeem-url.ts +14 -0
- package/src/preview/site-middleware.ts +60 -30
- package/src/preview-build.ts +85 -26
- package/src/preview-handler.astro +12 -9
- package/src/preview.ts +0 -1
- package/src/repository.ts +1 -1
- package/src/resolve-options.ts +37 -0
- package/src/site-id.ts +2 -4
- package/src/skill/SKILL.md +63 -55
- package/src/skill.ts +36 -8
- package/src/types.ts +33 -79
- package/src/virtual-modules.d.ts +4 -1
- package/dist/src/build-commit.d.ts +0 -19
- package/dist/src/build-commit.d.ts.map +0 -1
- package/dist/src/build-commit.js +0 -6
- package/dist/src/build-commit.js.map +0 -1
- package/dist/src/bundle.d.ts +0 -181
- package/dist/src/bundle.d.ts.map +0 -1
- package/dist/src/bundle.js +0 -413
- package/dist/src/bundle.js.map +0 -1
- package/dist/src/discovery.d.ts +0 -58
- package/dist/src/discovery.d.ts.map +0 -1
- package/dist/src/discovery.js +0 -133
- package/dist/src/discovery.js.map +0 -1
- package/dist/src/register.d.ts +0 -98
- package/dist/src/register.d.ts.map +0 -1
- package/dist/src/register.js +0 -103
- package/dist/src/register.js.map +0 -1
- package/src/build-commit.ts +0 -22
- package/src/bundle.ts +0 -570
- package/src/discovery.ts +0 -183
- package/src/register.ts +0 -180
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The org id as unpadded base64url: the form share links, entry codes and the grant cookie carry it in. */
|
|
2
|
+
export function orgToken(org: string): string {
|
|
3
|
+
let binary = '';
|
|
4
|
+
for (const byte of new TextEncoder().encode(org)) binary += String.fromCharCode(byte);
|
|
5
|
+
return btoa(binary).replace(/\+/gu, '-').replace(/\//gu, '_').replace(/=+$/u, '');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** `<orgToken>.<grantId>`: names one share link without naming the org in clear. */
|
|
9
|
+
export function grantRef(org: string, grantId: string): string {
|
|
10
|
+
return `${orgToken(org)}.${grantId}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A grant reference as the grant cookie holds it. */
|
|
14
|
+
export const GRANT_REF_RE = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{22}$/u;
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* Site-wide preview middleware for the recursive preview build — the SERVING
|
|
3
3
|
* SURFACE of draft preview.
|
|
4
4
|
*
|
|
5
|
-
* WHY THIS EXISTS — the
|
|
5
|
+
* WHY THIS EXISTS — the fixed preview route is an entry door, not the serving
|
|
6
6
|
* surface. Without this, preview survives exactly one page view: the visitor
|
|
7
|
-
* lands on `/
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* lands on `/_conloca/preview/about`, clicks a link, and the root-absolute
|
|
8
|
+
* `/blog` the site's template emitted drops the route and silently serves the
|
|
9
|
+
* PUBLISHED page. The preview cookie is already `Path=/`,
|
|
10
10
|
* so the browser is sending the credential on that request — this listens.
|
|
11
11
|
*
|
|
12
12
|
* WHY THE RENDER HAPPENS HERE, VIA `next()` — a middleware rewrite onto the
|
|
13
|
-
*
|
|
13
|
+
* preview route's handler (an earlier design) forced the render through
|
|
14
14
|
* `Astro.rewrite`, whose route matching does not fall through prerendered
|
|
15
15
|
* routes: with two root catch-alls (the CMS pages route on demand, a docs
|
|
16
16
|
* integration's route prerendered) the rewrite matched the prerendered one
|
|
@@ -27,17 +27,19 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import type { ContentAPI } from '@conloca/content-api';
|
|
30
|
-
import { fetchPageStatus, type PageStatus } from './_dispatch.js';
|
|
30
|
+
import { fetchPageStatus, isShareEndedKind, type PageStatus } from './_dispatch.js';
|
|
31
31
|
import { injectPreviewBanner } from './banner.js';
|
|
32
32
|
import { PreviewContentAPI } from './content-api.js';
|
|
33
|
-
import { applyPreviewHeaders } from './headers.js';
|
|
33
|
+
import { applyPreviewHeaders, PREVIEW_CACHE_HEADERS } from './headers.js';
|
|
34
|
+
import { renderPreviewUnavailable, renderShareEnded } from './landing.js';
|
|
35
|
+
import { handlePreviewRequest, type PreviewContext, type PreviewMiddlewareOptions } from './middleware.js';
|
|
34
36
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
normalizeTrailingSlash,
|
|
38
|
+
PREVIEW_SLUG_HEADER,
|
|
39
|
+
pathUnderBase,
|
|
40
|
+
previewScope,
|
|
41
|
+
stripPreviewPrefix,
|
|
42
|
+
} from './preview-path.js';
|
|
41
43
|
|
|
42
44
|
/** The subset of Astro's middleware context this middleware touches. */
|
|
43
45
|
export interface PreviewMiddlewareContext {
|
|
@@ -86,8 +88,8 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
86
88
|
// ALSO at build time, where Astro runs middleware while prerendering pages
|
|
87
89
|
// and the deployer's runtime vars do not exist yet. Neither is a reason to
|
|
88
90
|
// break the site's build or the whole site over a feature it may
|
|
89
|
-
// not use, so pass through and warn once. The
|
|
90
|
-
//
|
|
91
|
+
// not use, so pass through and warn once. The preview entry route still
|
|
92
|
+
// fails loudly: reaching it means someone explicitly asked to preview.
|
|
91
93
|
let opts: PreviewMiddlewareOptions;
|
|
92
94
|
try {
|
|
93
95
|
opts = resolveOpts();
|
|
@@ -96,30 +98,38 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
96
98
|
return next();
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
// Under D3 the dispatcher names the requested branch's slug, after stripping any the browser sent.
|
|
102
|
+
const slug = opts.mode === 'd3' ? (context.request.headers.get(PREVIEW_SLUG_HEADER) ?? undefined) : undefined;
|
|
99
103
|
const verdict = await handlePreviewRequest(context.request, {
|
|
100
104
|
...opts,
|
|
101
|
-
|
|
105
|
+
...(slug === undefined ? {} : { slug }),
|
|
106
|
+
// No silent fallback: under the slug, a pass that doesn't verify gets the landing page, never the
|
|
107
|
+
// published page at the draft URL. Only the live site's own requests (no slug) pass through.
|
|
108
|
+
onMiss: slug === undefined ? 'pass-through' : 'landing',
|
|
102
109
|
fetchFn: opts.fetchFn ?? seams.fetchFn,
|
|
103
110
|
});
|
|
104
111
|
if (verdict.kind === 'response') return verdict.response;
|
|
105
112
|
if (verdict.kind !== 'preview') return next();
|
|
113
|
+
// A preview verdict under D3 means the slug was named, so the scope always resolves.
|
|
114
|
+
const exitPath = `${previewScope(opts.mode ?? 'd2', opts.base, slug).route}/__exit`;
|
|
106
115
|
|
|
107
|
-
// A valid credential on the
|
|
108
|
-
//
|
|
109
|
-
//
|
|
116
|
+
// A valid credential on the preview route itself: canonicalize to the
|
|
117
|
+
// clean site path instead of rendering under the route — links, assets
|
|
118
|
+
// and the page lookup all assume clean paths.
|
|
110
119
|
const rawPath = context.url.pathname;
|
|
111
|
-
const path = normalizeTrailingSlash(stripPreviewPrefix(rawPath));
|
|
112
|
-
if (stripPreviewPrefix(rawPath) !== rawPath) {
|
|
120
|
+
const path = normalizeTrailingSlash(stripPreviewPrefix(rawPath, opts.base));
|
|
121
|
+
if (stripPreviewPrefix(rawPath, opts.base) !== rawPath) {
|
|
113
122
|
return new Response(null, {
|
|
114
123
|
status: 302,
|
|
115
|
-
headers: { location: path,
|
|
124
|
+
headers: { location: path, ...PREVIEW_CACHE_HEADERS },
|
|
116
125
|
});
|
|
117
126
|
}
|
|
118
127
|
|
|
119
128
|
context.locals.conlocaPreview = verdict.ctx;
|
|
120
|
-
// An endpoint failure (5xx mid-deploy, auth envelope, network) must
|
|
121
|
-
// the
|
|
122
|
-
//
|
|
129
|
+
// An endpoint failure (5xx mid-deploy, auth envelope, network) must neither
|
|
130
|
+
// 500 the site nor pass published bytes off as the draft: answer with a
|
|
131
|
+
// retry page that also offers Exit, since the visitor can't remove the
|
|
132
|
+
// HttpOnly cookie.
|
|
123
133
|
let status: PageStatus;
|
|
124
134
|
try {
|
|
125
135
|
status = await fetchPageStatus({
|
|
@@ -133,10 +143,21 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
133
143
|
});
|
|
134
144
|
} catch (error) {
|
|
135
145
|
console.warn(
|
|
136
|
-
`[@conloca/cloud-astro] preview page-status failed for ${path} —
|
|
146
|
+
`[@conloca/cloud-astro] preview page-status failed for ${path} — showing the retry page: ` +
|
|
137
147
|
`${error instanceof Error ? error.message : String(error)}`,
|
|
138
148
|
);
|
|
139
|
-
return
|
|
149
|
+
return renderPreviewUnavailable({
|
|
150
|
+
// Collapse leading slashes: `//evil.test/x` would otherwise be a cross-origin link.
|
|
151
|
+
retryHref: `/${rawPath.replace(/^\/+/u, '')}${context.url.search}`,
|
|
152
|
+
exitHref: `${exitPath}?to=${encodeURIComponent(rawPath)}`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (isShareEndedKind(status.kind) && 'sharedBy' in status) {
|
|
157
|
+
return renderShareEnded(status.kind, {
|
|
158
|
+
sharedBy: status.sharedBy,
|
|
159
|
+
liveHref: `${exitPath}?to=${encodeURIComponent(path)}`,
|
|
160
|
+
});
|
|
140
161
|
}
|
|
141
162
|
|
|
142
163
|
if (status.kind === 'unchanged') {
|
|
@@ -151,7 +172,7 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
151
172
|
// redirect can never be cached by intermediaries.
|
|
152
173
|
return new Response(null, {
|
|
153
174
|
status: 302,
|
|
154
|
-
headers: { location: status.target,
|
|
175
|
+
headers: { location: status.target, ...PREVIEW_CACHE_HEADERS },
|
|
155
176
|
});
|
|
156
177
|
}
|
|
157
178
|
|
|
@@ -180,11 +201,20 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
|
|
|
180
201
|
// through with the preview headers only.
|
|
181
202
|
return applyPreviewHeaders(rendered);
|
|
182
203
|
}
|
|
204
|
+
let shareUrl: string | undefined;
|
|
205
|
+
if (verdict.ctx.editorUrl !== undefined) {
|
|
206
|
+
const url = new URL(verdict.ctx.editorUrl);
|
|
207
|
+
url.searchParams.set('share', pathUnderBase(path, opts.base));
|
|
208
|
+
shareUrl = url.toString();
|
|
209
|
+
}
|
|
183
210
|
const html = injectPreviewBanner(
|
|
184
211
|
await rendered.text(),
|
|
185
212
|
verdict.ctx,
|
|
186
213
|
opts.saasEndpoint,
|
|
187
|
-
|
|
214
|
+
exitPath,
|
|
215
|
+
shareUrl,
|
|
216
|
+
// The page's own path: under D3 the address bar holds the route, which Edit and Exit must not carry.
|
|
217
|
+
rawPath,
|
|
188
218
|
);
|
|
189
219
|
return applyPreviewHeaders(new Response(html, { status: rendered.status, headers: rendered.headers }));
|
|
190
220
|
};
|
|
@@ -204,7 +234,7 @@ function warnUnconfiguredOnce(error: unknown): void {
|
|
|
204
234
|
console.warn(
|
|
205
235
|
`[@conloca/cloud-astro] draft preview is INERT — ${detail}\n` +
|
|
206
236
|
' Requests are being served as the ordinary published site.\n' +
|
|
207
|
-
'
|
|
237
|
+
' The preview server is missing its baked settings: rebuild with previewBuild given as an object ' +
|
|
208
238
|
'(see the cloud-astro README "Draft previews").',
|
|
209
239
|
);
|
|
210
240
|
}
|
package/src/preview-build.ts
CHANGED
|
@@ -1,10 +1,65 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
PACKAGE_NAME,
|
|
6
|
+
PREVIEW_BUILD_ENV_FLAG,
|
|
7
|
+
PREVIEW_MODE_ENV,
|
|
8
|
+
PREVIEW_PRERENDERED_ENV,
|
|
9
|
+
REFUSED_PREVIEW_ADAPTERS,
|
|
10
|
+
} from './constants.js';
|
|
11
|
+
import type { PreviewServeMode } from './preview/preview-path.js';
|
|
5
12
|
import type { PreviewBuildOptions } from './types.js';
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
/**
|
|
15
|
+
* How the preview build serves, from the options and the adapter the preview server would build with
|
|
16
|
+
* (`previewBuild.adapter`, else the project's own): off unless `previewBuild` is given as an object; D4 with
|
|
17
|
+
* `separate: true`; D3 for a static site, whose preview server runs next to it on Cloudflare Workers; D2 when an
|
|
18
|
+
* adapter is named, since the site's own server deploy serves the drafts. Throws for a refused adapter, so the build
|
|
19
|
+
* fails before it deploys anything.
|
|
20
|
+
*/
|
|
21
|
+
export function previewBuildMode(
|
|
22
|
+
previewBuild: PreviewBuildOptions | false | undefined,
|
|
23
|
+
adapterName: string | undefined,
|
|
24
|
+
): 'off' | PreviewServeMode {
|
|
25
|
+
if (!previewBuild) return 'off';
|
|
26
|
+
if (adapterName !== undefined && REFUSED_PREVIEW_ADAPTERS.includes(adapterName)) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`${PACKAGE_NAME}: previewBuild is not supported with ${adapterName} yet: that adapter writes its deployable ` +
|
|
29
|
+
'output at the project root, so the preview build could replace the live site. ' +
|
|
30
|
+
'Remove previewBuild from conlocaCloud(...).',
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (previewBuild.separate === true) return 'd4';
|
|
34
|
+
return adapterName === undefined ? 'd3' : 'd2';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The mode a preview build serves in: the site's build names D2 or D3; the flag alone is a separate preview deploy (D4). */
|
|
38
|
+
export function previewChildMode(env: NodeJS.ProcessEnv): PreviewServeMode {
|
|
39
|
+
const named = env[PREVIEW_MODE_ENV];
|
|
40
|
+
return named === 'd2' || named === 'd3' ? named : 'd4';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* One route the site's build prerendered, as a D3 child matches it: pattern and component together, since one
|
|
45
|
+
* entrypoint can be injected at two patterns, one published and one only the preview build has.
|
|
46
|
+
*/
|
|
47
|
+
export function prerenderedKey(pattern: string, component: string): string {
|
|
48
|
+
return JSON.stringify([pattern, component]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The routes (`prerenderedKey`) a D3 child's site build prerendered (`buildPreviewChildEnv`); none for any other child. */
|
|
52
|
+
export function previewChildPrerendered(env: NodeJS.ProcessEnv): Set<string> {
|
|
53
|
+
const text = env[PREVIEW_PRERENDERED_ENV];
|
|
54
|
+
if (previewChildMode(env) !== 'd3' || text === undefined) return new Set();
|
|
55
|
+
let value: unknown;
|
|
56
|
+
try {
|
|
57
|
+
value = JSON.parse(text);
|
|
58
|
+
} catch {
|
|
59
|
+
return new Set();
|
|
60
|
+
}
|
|
61
|
+
return new Set(Array.isArray(value) ? value.filter((item) => typeof item === 'string') : []);
|
|
62
|
+
}
|
|
8
63
|
|
|
9
64
|
/**
|
|
10
65
|
* The minimal child-process surface this module relies on. Letting
|
|
@@ -25,19 +80,24 @@ export type PreviewBuildSpawn = (
|
|
|
25
80
|
|
|
26
81
|
/**
|
|
27
82
|
* Pure constructor for the child-process environment passed to the recursive
|
|
28
|
-
* preview build. Extracted so tests can verify the contract (env flag +
|
|
29
|
-
*
|
|
83
|
+
* preview build. Extracted so tests can verify the contract (env flag +
|
|
84
|
+
* parent-env inheritance) without spinning up a child process — and so the
|
|
30
85
|
* real-process smoke test can call it the same way the integration does.
|
|
31
86
|
*
|
|
32
87
|
* Inherits the parent environment so PATH, credentials, and any host-specific
|
|
33
|
-
* build vars (CF_PAGES_*, GITHUB_*) reach the child
|
|
88
|
+
* build vars (CF_PAGES_*, WORKERS_CI_*, GITHUB_*) reach the child, which reads
|
|
89
|
+
* the branch and commit it serves from them.
|
|
34
90
|
*/
|
|
35
|
-
export function buildPreviewChildEnv(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
91
|
+
export function buildPreviewChildEnv(
|
|
92
|
+
parentEnv: NodeJS.ProcessEnv,
|
|
93
|
+
mode: 'd2' | 'd3' = 'd2',
|
|
94
|
+
prerendered: readonly string[] = [],
|
|
95
|
+
): NodeJS.ProcessEnv {
|
|
96
|
+
const env: NodeJS.ProcessEnv = { ...parentEnv, [PREVIEW_BUILD_ENV_FLAG]: '1', [PREVIEW_MODE_ENV]: mode };
|
|
97
|
+
// Only a D3 child reads it; a stale one from the environment must not reach a D2 child.
|
|
98
|
+
delete env[PREVIEW_PRERENDERED_ENV];
|
|
99
|
+
if (mode === 'd3') env[PREVIEW_PRERENDERED_ENV] = JSON.stringify(prerendered);
|
|
100
|
+
return env;
|
|
41
101
|
}
|
|
42
102
|
|
|
43
103
|
/**
|
|
@@ -71,13 +131,10 @@ export function resolveAstroBin(cwd: string = process.cwd()): string {
|
|
|
71
131
|
* Spawns the recursive preview `astro build` from the primary build's
|
|
72
132
|
* `astro:build:done` hook.
|
|
73
133
|
*
|
|
74
|
-
* The child process inherits the parent environment and additionally receives
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* - {@link PREVIEW_SECRET_ENV_FLAG} set to the per-branch secret so the
|
|
79
|
-
* child's `astro:config:setup` can inject the literal secret-scoped
|
|
80
|
-
* preview route (`/conloca_preview_${SECRET}/[...path]`).
|
|
134
|
+
* The child process inherits the parent environment and additionally receives
|
|
135
|
+
* {@link PREVIEW_BUILD_ENV_FLAG} set to `'1'`: the child's `astro:config:setup`
|
|
136
|
+
* mounts the preview route on it, and its `astro:build:done` short-circuits
|
|
137
|
+
* on it (recursion guard contract).
|
|
81
138
|
*
|
|
82
139
|
* If this function is itself called from within a recursive build (i.e. the
|
|
83
140
|
* env flag is already set to `'1'`), it returns immediately without spawning,
|
|
@@ -88,8 +145,12 @@ export function resolveAstroBin(cwd: string = process.cwd()): string {
|
|
|
88
145
|
* - `false` → resolves and logs a warning so onboarding setups can continue
|
|
89
146
|
* when the preview build is not yet wired correctly.
|
|
90
147
|
*/
|
|
91
|
-
export async function spawnPreviewBuild(
|
|
92
|
-
|
|
148
|
+
export async function spawnPreviewBuild(
|
|
149
|
+
opts: PreviewBuildOptions,
|
|
150
|
+
mode: 'd2' | 'd3' = 'd2',
|
|
151
|
+
prerendered: readonly string[] = [],
|
|
152
|
+
): Promise<void> {
|
|
153
|
+
await _spawnPreviewBuildWith(spawn, opts, mode, prerendered);
|
|
93
154
|
}
|
|
94
155
|
|
|
95
156
|
/**
|
|
@@ -100,10 +161,12 @@ export async function spawnPreviewBuild(previewSecret: string, opts: PreviewBuil
|
|
|
100
161
|
* and not part of the package's public surface; it is not re-exported from
|
|
101
162
|
* `src/index.ts` or `src/node.ts`.
|
|
102
163
|
*/
|
|
164
|
+
// oxlint-disable-next-line no-underscore-dangle -- the internal test seam.
|
|
103
165
|
export async function _spawnPreviewBuildWith(
|
|
104
166
|
spawnFn: PreviewBuildSpawn,
|
|
105
|
-
previewSecret: string,
|
|
106
167
|
opts: PreviewBuildOptions,
|
|
168
|
+
mode: 'd2' | 'd3' = 'd2',
|
|
169
|
+
prerendered: readonly string[] = [],
|
|
107
170
|
): Promise<void> {
|
|
108
171
|
// Recursion guard: bail out before doing any work if we're already inside
|
|
109
172
|
// a recursive preview build. This matches the short-circuit in the
|
|
@@ -112,15 +175,11 @@ export async function _spawnPreviewBuildWith(
|
|
|
112
175
|
return;
|
|
113
176
|
}
|
|
114
177
|
|
|
115
|
-
if (!previewSecret) {
|
|
116
|
-
throw new Error(`${PACKAGE_NAME}: preview secret is required to spawn the preview build`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
178
|
const required = opts.required ?? true;
|
|
120
179
|
|
|
121
180
|
const astroBin = resolveAstroBin();
|
|
122
181
|
const child = spawnFn(astroBin, ['build'], {
|
|
123
|
-
env: buildPreviewChildEnv(process.env,
|
|
182
|
+
env: buildPreviewChildEnv(process.env, mode, prerendered),
|
|
124
183
|
stdio: 'inherit',
|
|
125
184
|
});
|
|
126
185
|
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
---
|
|
2
2
|
import bakedPreviewOpts from 'virtual:conloca-preview-opts';
|
|
3
3
|
import { resolveEndpointFetch, resolveFromBaked } from './preview/_resolve-opts.js';
|
|
4
|
+
import { PREVIEW_CACHE_HEADERS } from './preview/headers.js';
|
|
4
5
|
import { stripPreviewPrefix } from './preview/preview-path.js';
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
* `/
|
|
8
|
-
*
|
|
7
|
+
* Entry route injected by the recursive preview build at the fixed, public
|
|
8
|
+
* `/_conloca/preview/[...path]` (under Astro's `base`). The route guards
|
|
9
|
+
* nothing: the signed pass is the lock, checked against the repository, site
|
|
10
|
+
* and branch this build was made from.
|
|
9
11
|
*
|
|
10
12
|
* This route is the ENTRY DOOR only; the site-wide middleware
|
|
11
13
|
* (`./site-middleware.ts`) is the serving surface. Three verdicts:
|
|
12
14
|
*
|
|
13
15
|
* 1. `response` — the query-token init hop (302 that sets the preview
|
|
14
16
|
* cookie and points at the clean path) or the no-preview landing page.
|
|
15
|
-
* 2. `preview` — a valid cookie on the
|
|
16
|
-
* with a 302 to the clean path. Rendering under the
|
|
17
|
+
* 2. `preview` — a valid cookie on the preview route itself: canonicalize
|
|
18
|
+
* with a 302 to the clean path. Rendering under the route is never
|
|
17
19
|
* correct (links/assets assume clean paths), and after the redirect the
|
|
18
20
|
* middleware serves the draft. Normally the middleware canonicalizes
|
|
19
21
|
* before this route runs — this branch is the defense-in-depth for an
|
|
@@ -25,8 +27,9 @@ import { stripPreviewPrefix } from './preview/preview-path.js';
|
|
|
25
27
|
import { handlePreviewRequest } from './preview.js';
|
|
26
28
|
|
|
27
29
|
// Same baked-then-env resolution the middleware uses, so the entry route and
|
|
28
|
-
// the serving surface can never disagree about
|
|
29
|
-
// missing
|
|
30
|
+
// the serving surface can never disagree about what this build serves. Throws
|
|
31
|
+
// loudly on a missing value: reaching this route means someone explicitly
|
|
32
|
+
// asked to preview.
|
|
30
33
|
const opts = resolveFromBaked(bakedPreviewOpts, (name) => process.env[name]);
|
|
31
34
|
const verdict = await handlePreviewRequest(Astro.request, {
|
|
32
35
|
...opts,
|
|
@@ -46,10 +49,10 @@ if (verdict.kind === 'pass-through') {
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
// verdict.kind === 'preview' — canonicalize to the clean site path.
|
|
49
|
-
const cleanPath = stripPreviewPrefix(Astro.originPathname ?? Astro.url.pathname);
|
|
52
|
+
const cleanPath = stripPreviewPrefix(Astro.originPathname ?? Astro.url.pathname, opts.base);
|
|
50
53
|
const canonical: Response = new Response(null, {
|
|
51
54
|
status: 302,
|
|
52
|
-
headers: { location: cleanPath,
|
|
55
|
+
headers: { location: cleanPath, ...PREVIEW_CACHE_HEADERS },
|
|
53
56
|
});
|
|
54
57
|
return canonical;
|
|
55
58
|
---
|
package/src/preview.ts
CHANGED
package/src/repository.ts
CHANGED
|
@@ -13,7 +13,7 @@ const REPO_SEGMENT = /^[A-Za-z0-9_.-]+$/;
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Normalize a provider full_name or common Git remote into `owner/repo`.
|
|
16
|
-
* Deliberately rejects local paths and nested groups:
|
|
16
|
+
* Deliberately rejects local paths and nested groups: the editor page names
|
|
17
17
|
* its repository GitHub-style, as two segments.
|
|
18
18
|
*/
|
|
19
19
|
export function normalizeRepositoryUri(input: string | undefined): string | undefined {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { EditorDescriptorChannel } from '@conloca/astro-cms/node';
|
|
2
|
+
import { PACKAGE_NAME } from './constants.js';
|
|
3
|
+
import type { ConlocaCloudOptions } from './types.js';
|
|
4
|
+
|
|
5
|
+
/** The editor options `conlocaCMS` already holds, settled for this build. */
|
|
6
|
+
export interface InheritedOptions {
|
|
7
|
+
puckConfigPath: string;
|
|
8
|
+
siteStyles?: string[];
|
|
9
|
+
editorStyles?: string[];
|
|
10
|
+
editorCss?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Each option given to `conlocaCloud()` wins; the channel `conlocaCMS`
|
|
15
|
+
* published fills the rest. `editorStyles` and `editorCss` come from the
|
|
16
|
+
* channel only. Only `puckConfigPath` is mandatory: without it there is no
|
|
17
|
+
* editor to build.
|
|
18
|
+
*/
|
|
19
|
+
export function resolveInheritedOptions(
|
|
20
|
+
options: Pick<ConlocaCloudOptions, 'puckConfigPath' | 'siteStyles'>,
|
|
21
|
+
channel: Pick<EditorDescriptorChannel, 'puckConfigPath' | 'siteStyles' | 'editorStyles' | 'editorCSS'> | undefined,
|
|
22
|
+
): InheritedOptions {
|
|
23
|
+
const puckConfigPath = options.puckConfigPath ?? channel?.puckConfigPath;
|
|
24
|
+
if (!puckConfigPath) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`${PACKAGE_NAME}: puckConfigPath is required: add it to conlocaCloud(), or add conlocaCMS() to this site's integrations`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const siteStyles =
|
|
30
|
+
typeof options.siteStyles === 'string' ? [options.siteStyles] : (options.siteStyles ?? channel?.siteStyles);
|
|
31
|
+
return {
|
|
32
|
+
puckConfigPath,
|
|
33
|
+
...(siteStyles === undefined ? {} : { siteStyles }),
|
|
34
|
+
...(channel?.editorStyles === undefined ? {} : { editorStyles: channel.editorStyles }),
|
|
35
|
+
...(channel?.editorCSS === undefined ? {} : { editorCss: channel.editorCSS }),
|
|
36
|
+
};
|
|
37
|
+
}
|
package/src/site-id.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { SITE_ID_RE } from '@conloca/content-api/editor-host';
|
|
3
4
|
import { PACKAGE_NAME } from './constants.js';
|
|
4
5
|
|
|
5
|
-
/** The site-id grammar: lowercase alphanumerics and dashes, 1-64 chars, alphanumeric first. */
|
|
6
|
-
export const SITE_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* Resolve the build's deployable-site id. STRICT: malformed input fails the
|
|
10
8
|
* build — a silent mis-attach is the same "deployed, but the editor points at
|
|
@@ -55,7 +53,7 @@ export function resolveBuildSiteId(opts: {
|
|
|
55
53
|
typeof record.sites !== 'object' ||
|
|
56
54
|
Array.isArray(record.sites)
|
|
57
55
|
) {
|
|
58
|
-
throw new Error(`${PACKAGE_NAME}: ${path} has no "sites" object — refusing to
|
|
56
|
+
throw new Error(`${PACKAGE_NAME}: ${path} has no "sites" object — refusing to build on a broken content model`);
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
let resolved: string;
|
package/src/skill/SKILL.md
CHANGED
|
@@ -1,69 +1,77 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: conloca-cloud
|
|
3
|
-
description: Load when a Conloca site uses @conloca/cloud-astro —
|
|
3
|
+
description: Load when a Conloca site uses @conloca/cloud-astro — conloca connect, the editor page, framing, doctor.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Connecting a site to
|
|
6
|
+
# Connecting a site to the workspace editor
|
|
7
7
|
|
|
8
|
-
`conlocaCloud(
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
`conlocaCloud()` from `@conloca/cloud-astro` is an add-on to `conlocaCMS(...)` — keep both in `integrations`, after
|
|
9
|
+
`react()`. It needs no options: it takes `puckConfigPath` and `siteStyles` from `conlocaCMS` and builds for the
|
|
10
|
+
workspace editor at `https://app.conloca.com`. Each `astro build` adds the editor page under `_conloca/editor/` in the
|
|
11
|
+
output; the workspace editor at `<slug>.conloca.com` opens the deployed page in a frame. Nothing else of it runs on the
|
|
12
|
+
published site. There is no build key, secret or environment variable.
|
|
11
13
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
For any question about the editor at `endpoint` — editor not loading, a stale editor after a deploy, "is this branch
|
|
15
|
-
registered?" — run this before reading source:
|
|
14
|
+
## Set up: connect → commit → push → deploy → open
|
|
16
15
|
|
|
17
16
|
```bash
|
|
18
|
-
|
|
19
|
-
conloca doctor # offline: config, token, endpoint, inert options
|
|
17
|
+
npx @conloca/cli connect # in the site's folder; add --yes when no terminal can answer
|
|
20
18
|
```
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
`
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
no other setup, no OIDC. Repository identity comes from CI metadata (`GITHUB_REPOSITORY`, Vercel, GitLab) or the git
|
|
31
|
-
remote; `repoUri` is only for non-standard checkouts. The `endpoint` is an https URL with no trailing slash.
|
|
32
|
-
|
|
33
|
-
**Whole-line gotcha:** the endpoint shows and copies the token as the line `CONLOCA_BUILD_TOKEN=cbt_…`. Pasted whole
|
|
34
|
-
into a secret's value, doctor CC2 reports it and the build's registration answers `401`; the token is fine — store only
|
|
35
|
-
the part from `cbt_`.
|
|
36
|
-
|
|
37
|
-
**Rotation gotcha:** creating a new token invalidates the old one. A `401` from the endpoint for a value that does start
|
|
38
|
-
with `cbt_` (doctor CC5) means the CI secret still holds a rotated token — create a new one and update the secret.
|
|
39
|
-
|
|
40
|
-
## The pipeline: build → register → editor
|
|
20
|
+
`connect` installs the packages, wires `astro.config` (writing `repoUri` from a GitHub `origin`), writes the site's host
|
|
21
|
+
into `sites.json`, adds a framing rule only where a committed header file forbids framing, builds once to check the
|
|
22
|
+
editor page, and removes old build key lines from workflows. It shows diffs first, keeps values you set (`differs`), and
|
|
23
|
+
exits `2` with the lines to add when a step needs a person (`--site-url https://…` when `astro.config` has no `site`).
|
|
24
|
+
It never commits, pushes or deploys: commit, push to the default branch, deploy as usual, then open the workspace
|
|
25
|
+
editor. Editing needs the deployed site; before that, `astro dev` serves the local editor at `/__cms`. Package updates
|
|
26
|
+
go through `npx @conloca/cli@latest upgrade` (or the exact version a Conloca prompt gave), never by editing `@conloca/*`
|
|
27
|
+
versions.
|
|
41
28
|
|
|
42
|
-
|
|
43
|
-
repo, git sha, branch, site id, and the bundle URL + hash.
|
|
44
|
-
2. The editor at `endpoint`, opened on a branch, loads the NEWEST registration for `(branch, site)`.
|
|
45
|
-
3. A build without a prerequisite (token, repo identity, sha/branch, public base URL) does not register; it warns and
|
|
46
|
-
ends with a summary block. Set `requireRegistration: true` in CI to fail such builds. A registration the endpoint
|
|
47
|
-
REJECTS always fails the build.
|
|
48
|
-
|
|
49
|
-
## Three states of a branch (doctor CC6)
|
|
50
|
-
|
|
51
|
-
- **Own registration** — the branch was built with the token; the editor loads its bundle.
|
|
52
|
-
- **Inherited** — no registration for this branch, but the default branch has one: the editor works from that bundle and
|
|
53
|
-
draft preview is degraded. Build the branch with the token to register it.
|
|
54
|
-
- **None** — neither: the editor will not load for this branch. Build it with the token.
|
|
55
|
-
|
|
56
|
-
Doctor may also report older registrations that are not active yet. They become active the next time the editor opens,
|
|
57
|
-
so a branch served only by them is a warning rather than "will not load" — it fails only if that branch has since grown
|
|
58
|
-
a second site.
|
|
59
|
-
|
|
60
|
-
## A deleted bundle (CC7)
|
|
29
|
+
## First move: `conloca doctor --live`
|
|
61
30
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
probes the bundle URL the registration names and says so: rebuild and deploy from that branch.
|
|
31
|
+
For any question about the workspace editor — "Connect this site" stays, the frame stays blank, old components after a
|
|
32
|
+
deploy — run this before reading source:
|
|
65
33
|
|
|
66
|
-
|
|
34
|
+
```bash
|
|
35
|
+
conloca doctor --live # sends no credential: only your site's host and the editor's /host/protocols.json
|
|
36
|
+
conloca doctor # offline: wiring, sites.json host, committed framing headers, key leftovers
|
|
37
|
+
```
|
|
67
38
|
|
|
68
|
-
|
|
69
|
-
|
|
39
|
+
This package's checks are `CC1` and `CC8`–`CC24`:
|
|
40
|
+
|
|
41
|
+
- **CC9** — `sites.json`: the site named `default` (or the only one) has a bare host in `domains[defaultLocale]` and a
|
|
42
|
+
valid `base`. The editor opens `https://<host><base>_conloca/editor/`; it refuses IPs, `localhost`, `*.conloca.com`.
|
|
43
|
+
- **CC10** — a committed `public/_headers`, `netlify.toml` or `vercel.json` sets `X-Frame-Options` or `frame-ancestors`
|
|
44
|
+
site-wide with no `/_conloca/editor/` rule. Fix: `connect`, or the rule the error prints.
|
|
45
|
+
- **CC11** (live) — `conloca.json` is deployed, public, and names this repository and site. "names no repository" → set
|
|
46
|
+
`repoUri` in `conlocaCloud(...)`. Serving an older commit than HEAD is a warning: deploy.
|
|
47
|
+
- **CC12** (live) — the deployed page may be framed by `https://*.conloca.com`, and its `script-src` allows the editor's
|
|
48
|
+
origin. Headers from host settings or a proxy show up only here.
|
|
49
|
+
- **CC13** (live) — the page's protocol is in the editor's range; too old → rebuild with a newer `@conloca/cloud-astro`.
|
|
50
|
+
- **CC14** — a workflow or the config still names `CONLOCA_BUILD_TOKEN`, `buildToken`, `publicBaseUrl`, `previewDomain`
|
|
51
|
+
or `requireRegistration`. Remove them; nothing reads them for the editor page.
|
|
52
|
+
- **CC15–CC21** — draft previews on a static site: `wrangler.jsonc` on Cloudflare Workers, wrangler ≥ 4.36, the
|
|
53
|
+
dispatcher `main`, `run_worker_first` covering the preview route and every on-demand route, no deploy redirect into
|
|
54
|
+
`.conloca/preview-server`, a 404 page, middleware negotiation, no tag manager. Fix:
|
|
55
|
+
`npx @conloca/cli connect --update --yes`, then deploy. A `wrangler.toml` must be converted to `wrangler.jsonc` first.
|
|
56
|
+
- **CC22–CC23** — the preview rate-limit binding (`conlocaPreviewLimit`, 60 per 10 s, in every env block) on the Paid
|
|
57
|
+
plan, none on the Free plan, and the Cloudflare plan recorded in `package.json` (`conloca.cfPlan`). Fix:
|
|
58
|
+
`connect --update --yes`; for the plan, ask the site's owner which plan the Cloudflare account is on and run
|
|
59
|
+
`connect --yes --cf-plan paid` (or `free`). On Free with API routes, CC23 warns that previews and those routes share
|
|
60
|
+
one daily request quota; Cloudflare Workers Paid removes the limit.
|
|
61
|
+
- **CC24** (live) — a separate preview deploy's `conloca.json` answers as D4.
|
|
62
|
+
|
|
63
|
+
## Framing: only when the site forbids it
|
|
64
|
+
|
|
65
|
+
A site sending no `X-Frame-Options` and no `frame-ancestors` needs nothing (GitHub Pages included). Otherwise
|
|
66
|
+
`/_conloca/editor/*` needs `Content-Security-Policy: frame-ancestors 'self' https://*.conloca.com`, plus
|
|
67
|
+
`/_conloca/editor/sandbox-frame.html` → `Content-Security-Policy: sandbox allow-scripts`. Cloudflare `_headers` also
|
|
68
|
+
detaches the site's headers on that path (`! X-Frame-Options`, `! Content-Security-Policy`); Netlify cannot detach;
|
|
69
|
+
Vercel uses `source: "/_conloca/editor/:path*"`. A site-wide CSP with `frame-ancestors` must be narrowed by hand — a
|
|
70
|
+
second policy cannot loosen it.
|
|
71
|
+
|
|
72
|
+
## Components come from the branch's deploy
|
|
73
|
+
|
|
74
|
+
On other branches the editor offers the components of the deploy whose code is closest to the branch's latest commit:
|
|
75
|
+
the branch's own deploy, the default branch's, or a build of the branch it was created from (labelled in the editor), on
|
|
76
|
+
a tie in that order, with a warning when the components may differ from the branch's code. Doctor's CC11 warning still
|
|
77
|
+
says which commit is live.
|