@conloca/cloud-astro 0.2.4 → 0.2.6
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 +69 -22
- package/dist/.build-inputs.json +36 -23
- package/dist/src/constants.d.ts +4 -4
- package/dist/src/constants.js +4 -4
- package/dist/src/d3-build.d.ts +6 -2
- package/dist/src/d3-build.d.ts.map +1 -1
- package/dist/src/d3-build.js +15 -11
- package/dist/src/d3-build.js.map +1 -1
- package/dist/src/d8-adapters.d.ts +10 -0
- package/dist/src/d8-adapters.d.ts.map +1 -0
- package/dist/src/d8-adapters.js +19 -0
- package/dist/src/d8-adapters.js.map +1 -0
- package/dist/src/d8-build.d.ts +99 -0
- package/dist/src/d8-build.d.ts.map +1 -0
- package/dist/src/d8-build.js +265 -0
- package/dist/src/d8-build.js.map +1 -0
- package/dist/src/d8-guards.d.ts +29 -0
- package/dist/src/d8-guards.d.ts.map +1 -0
- package/dist/src/d8-guards.js +145 -0
- package/dist/src/d8-guards.js.map +1 -0
- package/dist/src/d8-middleware.d.ts +7 -0
- package/dist/src/d8-middleware.d.ts.map +1 -0
- package/dist/src/d8-middleware.js +15 -0
- package/dist/src/d8-middleware.js.map +1 -0
- package/dist/src/d8-render.d.ts +9 -0
- package/dist/src/d8-render.d.ts.map +1 -0
- package/dist/src/d8-render.js +52 -0
- package/dist/src/d8-render.js.map +1 -0
- package/dist/src/doctor/checks-d8.d.ts +7 -0
- package/dist/src/doctor/checks-d8.d.ts.map +1 -0
- package/dist/src/doctor/checks-d8.js +240 -0
- package/dist/src/doctor/checks-d8.js.map +1 -0
- package/dist/src/doctor/checks-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-live.js +3 -5
- package/dist/src/doctor/checks-live.js.map +1 -1
- package/dist/src/doctor/checks-offline.d.ts +2 -0
- package/dist/src/doctor/checks-offline.d.ts.map +1 -1
- package/dist/src/doctor/checks-offline.js +17 -8
- package/dist/src/doctor/checks-offline.js.map +1 -1
- package/dist/src/doctor/checks-preview-live.d.ts +7 -2
- package/dist/src/doctor/checks-preview-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-preview-live.js +107 -7
- package/dist/src/doctor/checks-preview-live.js.map +1 -1
- package/dist/src/doctor/checks-preview.d.ts.map +1 -1
- package/dist/src/doctor/checks-preview.js +9 -4
- package/dist/src/doctor/checks-preview.js.map +1 -1
- package/dist/src/doctor/config-scan.d.ts +24 -6
- package/dist/src/doctor/config-scan.d.ts.map +1 -1
- package/dist/src/doctor/config-scan.js +89 -18
- 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 +2 -0
- package/dist/src/doctor/run.js.map +1 -1
- package/dist/src/doctor/types.d.ts +7 -0
- package/dist/src/doctor/types.d.ts.map +1 -1
- package/dist/src/doctor/types.js +7 -0
- package/dist/src/doctor/types.js.map +1 -1
- package/dist/src/editor-page/emit.d.ts +4 -3
- package/dist/src/editor-page/emit.d.ts.map +1 -1
- package/dist/src/editor-page/emit.js +9 -9
- package/dist/src/editor-page/emit.js.map +1 -1
- package/dist/src/integration.d.ts.map +1 -1
- package/dist/src/integration.js +228 -124
- package/dist/src/integration.js.map +1 -1
- package/dist/src/node.d.ts +2 -0
- package/dist/src/node.d.ts.map +1 -1
- package/dist/src/node.js +4 -0
- package/dist/src/node.js.map +1 -1
- package/dist/src/preview/_resolve-opts.d.ts +26 -1
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
- package/dist/src/preview/_resolve-opts.js.map +1 -1
- package/dist/src/preview/content-api.d.ts +15 -0
- package/dist/src/preview/content-api.d.ts.map +1 -1
- package/dist/src/preview/content-api.js +57 -6
- package/dist/src/preview/content-api.js.map +1 -1
- package/dist/src/preview/d8-middleware.d.ts +25 -0
- package/dist/src/preview/d8-middleware.d.ts.map +1 -0
- package/dist/src/preview/d8-middleware.js +94 -0
- package/dist/src/preview/d8-middleware.js.map +1 -0
- package/dist/src/preview/dispatcher.d.ts +3 -16
- package/dist/src/preview/dispatcher.d.ts.map +1 -1
- package/dist/src/preview/dispatcher.js +46 -134
- package/dist/src/preview/dispatcher.js.map +1 -1
- package/dist/src/preview/headers.d.ts +3 -0
- package/dist/src/preview/headers.d.ts.map +1 -1
- package/dist/src/preview/headers.js +10 -1
- package/dist/src/preview/headers.js.map +1 -1
- package/dist/src/preview/links.d.ts +23 -0
- package/dist/src/preview/links.d.ts.map +1 -0
- package/dist/src/preview/links.js +168 -0
- package/dist/src/preview/links.js.map +1 -0
- package/dist/src/preview/middleware.d.ts +9 -3
- package/dist/src/preview/middleware.d.ts.map +1 -1
- package/dist/src/preview/middleware.js +36 -16
- package/dist/src/preview/middleware.js.map +1 -1
- package/dist/src/preview/prefix-router.d.ts +67 -0
- package/dist/src/preview/prefix-router.d.ts.map +1 -0
- package/dist/src/preview/prefix-router.js +153 -0
- package/dist/src/preview/prefix-router.js.map +1 -0
- package/dist/src/preview/preview-path.d.ts +8 -3
- package/dist/src/preview/preview-path.d.ts.map +1 -1
- package/dist/src/preview/preview-path.js +16 -4
- package/dist/src/preview/preview-path.js.map +1 -1
- package/dist/src/preview/site-middleware.d.ts +8 -2
- package/dist/src/preview/site-middleware.d.ts.map +1 -1
- package/dist/src/preview/site-middleware.js +90 -31
- package/dist/src/preview/site-middleware.js.map +1 -1
- package/dist/src/preview/site-page-sources.d.ts +21 -0
- package/dist/src/preview/site-page-sources.d.ts.map +1 -0
- package/dist/src/preview/site-page-sources.js +129 -0
- package/dist/src/preview/site-page-sources.js.map +1 -0
- package/dist/src/preview/site-pages.d.ts +18 -0
- package/dist/src/preview/site-pages.d.ts.map +1 -0
- package/dist/src/preview/site-pages.js +7 -0
- package/dist/src/preview/site-pages.js.map +1 -0
- package/dist/src/preview-build.d.ts +17 -16
- package/dist/src/preview-build.d.ts.map +1 -1
- package/dist/src/preview-build.js +37 -40
- package/dist/src/preview-build.js.map +1 -1
- package/dist/src/preview-image-endpoint.d.ts +8 -0
- package/dist/src/preview-image-endpoint.d.ts.map +1 -0
- package/dist/src/preview-image-endpoint.js +34 -0
- package/dist/src/preview-image-endpoint.js.map +1 -0
- package/dist/src/preview-render-seams.d.ts +7 -0
- package/dist/src/preview-render-seams.d.ts.map +1 -0
- package/dist/src/preview-render-seams.js +27 -0
- package/dist/src/preview-render-seams.js.map +1 -0
- package/dist/src/site-middleware.d.ts +2 -4
- package/dist/src/site-middleware.d.ts.map +1 -1
- package/dist/src/site-middleware.js +6 -22
- package/dist/src/site-middleware.js.map +1 -1
- package/dist/src/types.d.ts +15 -16
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +138 -6
- package/src/constants.ts +4 -4
- package/src/d3-build.ts +20 -14
- package/src/d8-adapters.ts +19 -0
- package/src/d8-build.ts +356 -0
- package/src/d8-guards.ts +177 -0
- package/src/d8-middleware.ts +17 -0
- package/src/d8-render.ts +61 -0
- package/src/doctor/checks-d8.ts +256 -0
- package/src/doctor/checks-live.ts +3 -4
- package/src/doctor/checks-offline.ts +21 -8
- package/src/doctor/checks-preview-live.ts +114 -8
- package/src/doctor/checks-preview.ts +9 -4
- package/src/doctor/config-scan.ts +86 -15
- package/src/doctor/run.ts +2 -0
- package/src/doctor/types.ts +8 -0
- package/src/editor-page/emit.ts +23 -14
- package/src/integration.ts +274 -135
- package/src/node.ts +4 -0
- package/src/preview/_resolve-opts.ts +17 -1
- package/src/preview/content-api.ts +60 -5
- package/src/preview/d8-middleware.ts +124 -0
- package/src/preview/dispatcher.ts +55 -150
- package/src/preview/headers.ts +10 -1
- package/src/preview/links.ts +175 -0
- package/src/preview/middleware.ts +41 -19
- package/src/preview/prefix-router.ts +197 -0
- package/src/preview/preview-path.ts +24 -6
- package/src/preview/site-middleware.ts +109 -38
- package/src/preview/site-page-sources.ts +146 -0
- package/src/preview/site-pages.ts +22 -0
- package/src/preview-build.ts +43 -42
- package/src/preview-image-endpoint.ts +35 -0
- package/src/preview-render-seams.ts +31 -0
- package/src/site-middleware.ts +6 -24
- package/src/skill/SKILL.md +19 -1
- package/src/types.ts +15 -16
- package/src/virtual-modules.d.ts +17 -2
package/src/site-middleware.ts
CHANGED
|
@@ -5,27 +5,22 @@
|
|
|
5
5
|
* the integration resolves to this module, so it must export `onRequest` —
|
|
6
6
|
* Astro's middleware contract. The verdict/render logic lives in
|
|
7
7
|
* `./preview/site-middleware.ts`, which is env-free and unit-testable; this
|
|
8
|
-
* file binds it to the runtime env resolution and to the
|
|
9
|
-
*
|
|
10
|
-
* here, so the collection-backed baseline is constructed here and injected as
|
|
11
|
-
* a seam.
|
|
8
|
+
* file binds it to the runtime env resolution and to the render seams built
|
|
9
|
+
* from the site's own build graph (`./preview-render-seams.ts`).
|
|
12
10
|
*
|
|
13
11
|
* Mounted ONLY inside the preview build (see `integration.ts`), never in the
|
|
14
12
|
* site's production build.
|
|
15
13
|
*/
|
|
16
14
|
|
|
17
|
-
import { getCollection } from 'astro:content';
|
|
18
15
|
import baked from 'virtual:conloca-preview-opts';
|
|
19
|
-
import
|
|
20
|
-
import { createCollectionBackedContentAPI } from '@conloca/astro-cms';
|
|
21
|
-
import type { ContentAPI } from '@conloca/content-api';
|
|
22
|
-
import { resolveEndpointFetch, resolveFromBaked } from './preview/_resolve-opts.js';
|
|
16
|
+
import { resolveFromBaked } from './preview/_resolve-opts.js';
|
|
23
17
|
import {
|
|
24
18
|
createPreviewSiteMiddleware,
|
|
25
19
|
type PreviewMiddlewareContext,
|
|
26
20
|
type PreviewMiddlewareNext,
|
|
27
21
|
} from './preview/site-middleware.js';
|
|
28
22
|
import { untagWorkerdProcess } from './preview/workerd-shim.js';
|
|
23
|
+
import { previewRenderSeams } from './preview-render-seams.js';
|
|
29
24
|
|
|
30
25
|
// At Cloudflare Worker start-up, before any render: workerd's nodejs_compat
|
|
31
26
|
// process can masquerade as Node's, sending Astro down a streaming branch whose
|
|
@@ -33,23 +28,10 @@ import { untagWorkerdProcess } from './preview/workerd-shim.js';
|
|
|
33
28
|
// literal string "[object Object]". See the shim's doc for the full chain.
|
|
34
29
|
untagWorkerdProcess();
|
|
35
30
|
|
|
36
|
-
// One baseline per process: the built collections are immutable at runtime,
|
|
37
|
-
// and constructing the collection-backed reader walks every collection.
|
|
38
|
-
let baselinePromise: Promise<ContentAPI> | undefined;
|
|
39
|
-
function baselineApi(): Promise<ContentAPI> {
|
|
40
|
-
baselinePromise ??= createCollectionBackedContentAPI({
|
|
41
|
-
getCollection: (name) => getCollection(name),
|
|
42
|
-
routing: routingConfig,
|
|
43
|
-
});
|
|
44
|
-
return baselinePromise;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
31
|
export async function onRequest(context: PreviewMiddlewareContext, next: PreviewMiddlewareNext): Promise<Response> {
|
|
48
32
|
const handler = createPreviewSiteMiddleware(() => resolveFromBaked(baked, (name) => process.env[name]), {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
locale: routingConfig.locale,
|
|
52
|
-
fetchFn: await resolveEndpointFetch(),
|
|
33
|
+
...(await previewRenderSeams()),
|
|
34
|
+
baked,
|
|
53
35
|
});
|
|
54
36
|
return handler(context, next);
|
|
55
37
|
}
|
package/src/skill/SKILL.md
CHANGED
|
@@ -36,7 +36,7 @@ conloca doctor --live # sends no credential: only your site's host and the e
|
|
|
36
36
|
conloca doctor # offline: wiring, sites.json host, committed framing headers, key leftovers
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
This package's checks are `CC1` and `CC8`–`
|
|
39
|
+
This package's checks are `CC1` and `CC8`–`CC29`:
|
|
40
40
|
|
|
41
41
|
- **CC9** — `sites.json`: the site named `default` (or the only one) has a bare host in `domains[defaultLocale]` and a
|
|
42
42
|
valid `base`. The editor opens `https://<host><base>_conloca/editor/`; it refuses IPs, `localhost`, `*.conloca.com`.
|
|
@@ -59,6 +59,24 @@ This package's checks are `CC1` and `CC8`–`CC24`:
|
|
|
59
59
|
`connect --yes --cf-plan paid` (or `free`). On Free with API routes, CC23 warns that previews and those routes share
|
|
60
60
|
one daily request quota; Cloudflare Workers Paid removes the limit.
|
|
61
61
|
- **CC24** (live) — a separate preview deploy's `conloca.json` answers as D4.
|
|
62
|
+
- **CC25–CC28** — draft previews in the site's own build (d8): one of the four official adapters, in the tested release
|
|
63
|
+
range, on an astro at or above its floor; nothing that turns preview off (`isr` without the preview route excluded,
|
|
64
|
+
edge middleware, `previewBuild.adapter`, `separate: true` under Vercel or Netlify); the host's routing (Vercel
|
|
65
|
+
`build.format: 'file'`, `site` on Vercel and Netlify, a static Cloudflare site's `run_worker_first` and `"404-page"`);
|
|
66
|
+
`security.allowedDomains` on `@astrojs/node`. Fix: `npx @conloca/cli connect` (adds the adapter and its options).
|
|
67
|
+
- **CC29** (live) — `<host><base>_conloca/preview/__exit` answers 302, uncached, as the configured mode. A failure names
|
|
68
|
+
where the host keeps logs; a 401/403/429 means something in front of the site blocks `/_conloca/preview/*`.
|
|
69
|
+
|
|
70
|
+
## Draft previews in the site's own build (d8)
|
|
71
|
+
|
|
72
|
+
- Updating `@conloca/cloud-astro` switches a D2 site (preview from its own server) and an `@astrojs/cloudflare`
|
|
73
|
+
server-rendered site to d8 on the next build. Run `npx @conloca/cli upgrade` for the edits: the start command moves to
|
|
74
|
+
`node dist/server/entry.mjs`, and the `previewBuild` options d8 ignores go.
|
|
75
|
+
- Read `Astro.locals.contentApi` inside each request. Never cache it, or anything read from it, at module level: on a
|
|
76
|
+
server-rendered site drafts and published pages share one warm function.
|
|
77
|
+
- A static Vercel site adds a `src/pages/404` page, or every miss runs the preview function.
|
|
78
|
+
- Vercel and Netlify sites set `site` in `astro.config` so their own pages stay inside the preview. `site` also changes
|
|
79
|
+
canonical, sitemap, RSS and Open Graph URLs on the live pages: ask the site owner first.
|
|
62
80
|
|
|
63
81
|
## Framing: only when the site forbids it
|
|
64
82
|
|
package/src/types.ts
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
import type { AstroIntegration } from 'astro';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* Cloudflare Workers under `/_conloca/preview/` next to the site (it needs `@astrojs/cloudflare` installed); a site
|
|
6
|
-
* with an adapter
|
|
7
|
-
*
|
|
4
|
+
* Draft previews. Off unless given as an object. A static site's preview server is a second build that runs on
|
|
5
|
+
* Cloudflare Workers under `/_conloca/preview/` next to the site (D3; it needs `@astrojs/cloudflare` installed); a site
|
|
6
|
+
* with an adapter renders drafts in its own build (D8); `separate: true` builds a separate preview deploy (D4).
|
|
7
|
+
* `config` and `outDir` belong to D3 and D4 only (a D8 build warns they have no effect); `required` is ignored in every
|
|
8
|
+
* mode, with a warning. `separate` is
|
|
9
|
+
* refused under `@astrojs/vercel` and `@astrojs/netlify`.
|
|
8
10
|
*/
|
|
9
11
|
export interface PreviewBuildOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Optional alternative Astro adapter to use for the preview build.
|
|
12
|
-
* Falls back to the project's default adapter when omitted.
|
|
13
|
-
*/
|
|
12
|
+
/** Refused: drafts render through the adapter in astro.config. Kept in the type so the refusal can name it. */
|
|
14
13
|
adapter?: AstroIntegration;
|
|
15
14
|
/**
|
|
16
|
-
* Adapter-specific config overrides forwarded to the
|
|
15
|
+
* Adapter-specific config overrides forwarded to the D3 or D4 preview build.
|
|
17
16
|
*/
|
|
18
17
|
config?: Record<string, unknown>;
|
|
19
18
|
/**
|
|
20
|
-
* Output directory for the preview build. Defaults to `.conloca/preview-server`
|
|
19
|
+
* Output directory for the D3 or D4 preview build. Defaults to `.conloca/preview-server`
|
|
21
20
|
* — outside `dist/`, so the preview server can never ride a wholesale static
|
|
22
21
|
* upload of the site and Astro's dist-clearing cannot wipe it.
|
|
23
22
|
*/
|
|
24
23
|
outDir?: string;
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
25
|
+
* Ignored in every mode (the build warns). A failed D3 preview build fails the site's build only when its server also
|
|
26
|
+
* serves the live site (`run_worker_first` lists routes beyond the preview route, or `not_found_handling` is
|
|
27
|
+
* `"none"`); otherwise the site ships and its preview route answers "preview unavailable". A D4 build is its deploy's
|
|
28
|
+
* own.
|
|
30
29
|
*/
|
|
31
30
|
required?: boolean;
|
|
32
31
|
/**
|
|
@@ -79,8 +78,8 @@ export interface ConlocaCloudOptions {
|
|
|
79
78
|
*/
|
|
80
79
|
siteStyles?: string | string[];
|
|
81
80
|
/**
|
|
82
|
-
* Off unless given as an object
|
|
83
|
-
*
|
|
81
|
+
* Off unless given as an object: draft previews in the site's own build (d8, with an adapter), next to a static
|
|
82
|
+
* site (D3) or from a separate deploy (D4). `separate` is refused under @astrojs/vercel and @astrojs/netlify.
|
|
84
83
|
*/
|
|
85
84
|
previewBuild?: PreviewBuildOptions | false;
|
|
86
85
|
/**
|
package/src/virtual-modules.d.ts
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* augmenting an existing module rather than declaring a new ambient one.
|
|
7
7
|
*
|
|
8
8
|
* `virtual:conloca-preview-opts` carries the preview middleware's configuration
|
|
9
|
-
* baked in during the
|
|
10
|
-
* runtime env vars. It resolves to `{}` outside
|
|
9
|
+
* baked in during the preview build (or a d8 site's own build), so a preview
|
|
10
|
+
* deployment needs no runtime env vars. It resolves to `{}` outside those builds.
|
|
11
|
+
* Mirrors `BakedPreviewOpts`.
|
|
11
12
|
*/
|
|
12
13
|
declare module 'virtual:conloca-preview-opts' {
|
|
13
14
|
const baked: {
|
|
@@ -19,6 +20,15 @@ declare module 'virtual:conloca-preview-opts' {
|
|
|
19
20
|
siteId?: string;
|
|
20
21
|
branch?: string;
|
|
21
22
|
base?: string;
|
|
23
|
+
mode?: 'd2' | 'd3' | 'd4' | 'd8';
|
|
24
|
+
domains?: string[];
|
|
25
|
+
trailingSlash?: 'always' | 'never' | 'ignore';
|
|
26
|
+
sitePages?:
|
|
27
|
+
| { kind: 'disk'; serverEntry: string }
|
|
28
|
+
| { kind: 'assets' }
|
|
29
|
+
| { kind: 'function'; serverEntry: string; origin: string | null }
|
|
30
|
+
| { kind: 'none' };
|
|
31
|
+
buildFormat?: 'directory' | 'file' | 'preserve';
|
|
22
32
|
};
|
|
23
33
|
export default baked;
|
|
24
34
|
}
|
|
@@ -44,6 +54,11 @@ declare module 'astro:content' {
|
|
|
44
54
|
export function getCollection(collection: string): Promise<{ data: Record<string, unknown> }[]>;
|
|
45
55
|
}
|
|
46
56
|
|
|
57
|
+
/** Astro's assets module, resolvable only inside a site build: the image config the preview image endpoint checks. */
|
|
58
|
+
declare module 'astro:assets' {
|
|
59
|
+
export const imageConfig: import('astro').AstroConfig['image'];
|
|
60
|
+
}
|
|
61
|
+
|
|
47
62
|
/**
|
|
48
63
|
* The Cloudflare Workers runtime module (bindings live here since Astro v6
|
|
49
64
|
* removed `locals.runtime.env`). Only resolvable inside workerd; the preview
|