@astrale-os/adapter-cloudflare 0.4.9 → 0.5.0-beta.1
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/build/codegen/identity.d.ts.map +1 -0
- package/dist/build/codegen/identity.js.map +1 -0
- package/dist/build/codegen/merge.d.ts.map +1 -0
- package/dist/build/codegen/merge.js.map +1 -0
- package/dist/build/codegen/worker.d.ts +12 -0
- package/dist/build/codegen/worker.d.ts.map +1 -0
- package/dist/build/codegen/worker.js +40 -0
- package/dist/build/codegen/worker.js.map +1 -0
- package/dist/{codegen → build/codegen}/wrangler.d.ts +6 -3
- package/dist/build/codegen/wrangler.d.ts.map +1 -0
- package/dist/{codegen → build/codegen}/wrangler.js +29 -10
- package/dist/build/codegen/wrangler.js.map +1 -0
- package/dist/build/frontend.d.ts +26 -0
- package/dist/build/frontend.d.ts.map +1 -0
- package/dist/build/frontend.js +263 -0
- package/dist/build/frontend.js.map +1 -0
- package/dist/{build.js → build/index.d.ts} +5 -4
- package/dist/build/index.d.ts.map +1 -0
- package/dist/{build.d.ts → build/index.js} +5 -5
- package/dist/build/index.js.map +1 -0
- package/dist/{parse-output.d.ts → build/parse-output.d.ts} +2 -0
- package/dist/build/parse-output.d.ts.map +1 -0
- package/dist/{parse-output.js → build/parse-output.js} +5 -0
- package/dist/build/parse-output.js.map +1 -0
- package/dist/build/prepare.d.ts +18 -0
- package/dist/build/prepare.d.ts.map +1 -0
- package/dist/build/prepare.js +117 -0
- package/dist/build/prepare.js.map +1 -0
- package/dist/build/worker.d.ts +15 -0
- package/dist/build/worker.d.ts.map +1 -0
- package/dist/build/worker.js +21 -0
- package/dist/build/worker.js.map +1 -0
- package/dist/{wrangler-cli.d.ts → build/wrangler-cli.d.ts} +8 -0
- package/dist/build/wrangler-cli.d.ts.map +1 -0
- package/dist/{wrangler-cli.js → build/wrangler-cli.js} +28 -4
- package/dist/build/wrangler-cli.js.map +1 -0
- package/dist/cloudflare.d.ts +21 -24
- package/dist/cloudflare.d.ts.map +1 -1
- package/dist/cloudflare.js +125 -191
- package/dist/cloudflare.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/params.d.ts +13 -16
- package/dist/params.d.ts.map +1 -1
- package/dist/worker/index.d.ts +48 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +186 -0
- package/dist/worker/index.js.map +1 -0
- package/package.json +13 -5
- package/src/build/codegen/worker.ts +53 -0
- package/src/{codegen → build/codegen}/wrangler.ts +34 -12
- package/src/build/frontend.ts +324 -0
- package/src/{build.ts → build/index.ts} +17 -4
- package/src/{parse-output.ts → build/parse-output.ts} +6 -0
- package/src/build/prepare.ts +161 -0
- package/src/build/worker.ts +37 -0
- package/src/{wrangler-cli.ts → build/wrangler-cli.ts} +44 -6
- package/src/cloudflare.ts +153 -223
- package/src/index.ts +4 -4
- package/src/params.ts +13 -17
- package/src/worker/index.ts +278 -0
- package/src/worker/tsconfig.json +10 -0
- package/template/astrale.config.ts +7 -7
- package/dist/assets-pack.d.ts +0 -8
- package/dist/assets-pack.d.ts.map +0 -1
- package/dist/assets-pack.js +0 -30
- package/dist/assets-pack.js.map +0 -1
- package/dist/build.d.ts.map +0 -1
- package/dist/build.js.map +0 -1
- package/dist/client.d.ts +0 -17
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -59
- package/dist/client.js.map +0 -1
- package/dist/codegen/identity.d.ts.map +0 -1
- package/dist/codegen/identity.js.map +0 -1
- package/dist/codegen/merge.d.ts.map +0 -1
- package/dist/codegen/merge.js.map +0 -1
- package/dist/codegen/worker.d.ts +0 -51
- package/dist/codegen/worker.d.ts.map +0 -1
- package/dist/codegen/worker.js +0 -120
- package/dist/codegen/worker.js.map +0 -1
- package/dist/codegen/wrangler.d.ts.map +0 -1
- package/dist/codegen/wrangler.js.map +0 -1
- package/dist/parse-output.d.ts.map +0 -1
- package/dist/parse-output.js.map +0 -1
- package/dist/wrangler-cli.d.ts.map +0 -1
- package/dist/wrangler-cli.js.map +0 -1
- package/src/assets-pack.ts +0 -32
- package/src/client.ts +0 -89
- package/src/codegen/worker.ts +0 -136
- package/template/.env.example +0 -9
- package/template/CLAUDE.md +0 -13
- package/template/README.md +0 -47
- package/template/client/__tests__/app.test.tsx +0 -15
- package/template/client/components.json +0 -25
- package/template/client/index.html +0 -12
- package/template/client/package.json +0 -35
- package/template/client/src/app.tsx +0 -52
- package/template/client/src/components/ui/cn.ts +0 -6
- package/template/client/src/main.tsx +0 -9
- package/template/client/src/styles.css +0 -78
- package/template/client/tsconfig.json +0 -26
- package/template/client/vite.config.ts +0 -22
- package/template/client/vitest.config.ts +0 -13
- package/template/core/README.md +0 -7
- package/template/deps.ts +0 -9
- package/template/domain.ts +0 -11
- package/template/env.ts +0 -8
- package/template/icons.ts +0 -4
- package/template/integrations/README.md +0 -7
- package/template/oxlint.config.ts +0 -1
- package/template/package.json +0 -57
- package/template/pnpm-workspace.yaml +0 -44
- package/template/runtime/index.ts +0 -8
- package/template/schema/index.ts +0 -10
- package/template/simulation/README.md +0 -12
- package/template/tsconfig.json +0 -28
- package/template/vitest.config.ts +0 -7
- /package/dist/{codegen → build/codegen}/identity.d.ts +0 -0
- /package/dist/{codegen → build/codegen}/identity.js +0 -0
- /package/dist/{codegen → build/codegen}/merge.d.ts +0 -0
- /package/dist/{codegen → build/codegen}/merge.js +0 -0
- /package/src/{codegen → build/codegen}/identity.ts +0 -0
- /package/src/{codegen → build/codegen}/merge.ts +0 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { issuer } from '@astrale-os/kernel-core/auth';
|
|
2
|
+
import { createRemoteApplication } from '@astrale-os/sdk/server';
|
|
3
|
+
import { Hono as HonoApplication } from 'hono';
|
|
4
|
+
const MAXIMUM_CACHED_APPLICATIONS = 4;
|
|
5
|
+
const APPLICATION_CLOSE_TIMEOUT_MS = 5_000;
|
|
6
|
+
/**
|
|
7
|
+
* Compose one Cloudflare module Worker without request-global mutation.
|
|
8
|
+
* Environment bindings are captured once per immutable serving URL/version generation.
|
|
9
|
+
*/
|
|
10
|
+
export function cloudflareWorkerEntry() {
|
|
11
|
+
return function (config) {
|
|
12
|
+
const applications = new Map();
|
|
13
|
+
const applicationFor = async (url, bindings) => {
|
|
14
|
+
const version = deploymentVersion(bindings);
|
|
15
|
+
const key = `${url}\u0000${version}`;
|
|
16
|
+
const cached = applications.get(key);
|
|
17
|
+
if (cached !== undefined)
|
|
18
|
+
return cached;
|
|
19
|
+
const environment = config.resolveEnvironment === undefined
|
|
20
|
+
? bindings
|
|
21
|
+
: await config.resolveEnvironment(bindings);
|
|
22
|
+
const routedFetch = async (input, init) => {
|
|
23
|
+
const request = new Request(input, init);
|
|
24
|
+
const destination = new URL(request.url);
|
|
25
|
+
if (destination.origin === new URL(url).origin) {
|
|
26
|
+
const self = config.selfBinding?.(bindings);
|
|
27
|
+
if (self !== null && self !== undefined)
|
|
28
|
+
return self.fetch(request);
|
|
29
|
+
return serving.app.fetch(request, environment);
|
|
30
|
+
}
|
|
31
|
+
const route = config.routeSubrequest?.(destination, bindings);
|
|
32
|
+
return route === null || route === undefined ? fetch(request) : route.fetch(request);
|
|
33
|
+
};
|
|
34
|
+
const deploymentQuery = `deployment=${encodeURIComponent(version)}`;
|
|
35
|
+
const issuerId = issuer.accept(url);
|
|
36
|
+
const host = new HonoApplication();
|
|
37
|
+
host.get('/meta', (context) => context.json({
|
|
38
|
+
origin: config.definition.schema.origin,
|
|
39
|
+
issuer: issuerId,
|
|
40
|
+
schemaRevision: config.definition.domain.$.revision,
|
|
41
|
+
deploymentVersion: version,
|
|
42
|
+
}));
|
|
43
|
+
const serving = createRemoteApplication({
|
|
44
|
+
definition: config.definition,
|
|
45
|
+
environment,
|
|
46
|
+
identity: {
|
|
47
|
+
issuer: issuerId,
|
|
48
|
+
subject: config.definition.schema.origin,
|
|
49
|
+
privateKey: typeof config.privateKey === 'function'
|
|
50
|
+
? config.privateKey(bindings)
|
|
51
|
+
: config.privateKey,
|
|
52
|
+
fetch: routedFetch,
|
|
53
|
+
...(new URL(url).protocol === 'http:' ? { allowInsecureHttp: true } : {}),
|
|
54
|
+
},
|
|
55
|
+
deployment: {
|
|
56
|
+
bundleHref: `${url}/.well-known/astrale/domain.bundle.json?${deploymentQuery}`,
|
|
57
|
+
endpoint: { http: `${url}/invoke` },
|
|
58
|
+
...(config.definition.frontend === undefined
|
|
59
|
+
? {}
|
|
60
|
+
: { frontendBaseHref: url, frontendCacheKey: version }),
|
|
61
|
+
...(config.manifest === undefined ? {} : { manifest: config.manifest }),
|
|
62
|
+
installation: {
|
|
63
|
+
href: `${url}/install`,
|
|
64
|
+
method: 'POST',
|
|
65
|
+
authentication: { kind: 'public' },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
app: host,
|
|
69
|
+
server: {
|
|
70
|
+
path: '/invoke',
|
|
71
|
+
health: { probe: { check: () => true } },
|
|
72
|
+
limits: {
|
|
73
|
+
maximumRequestBytes: 1024 * 1024,
|
|
74
|
+
maximumPublicationBytes: 1024 * 1024,
|
|
75
|
+
maximumBundleBytes: 8 * 1024 * 1024,
|
|
76
|
+
maximumInstallationBytes: 8 * 1024 * 1024,
|
|
77
|
+
invocationTimeoutMs: 30_000,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const created = Object.freeze({
|
|
82
|
+
origin: new URL(url).origin,
|
|
83
|
+
application: serving,
|
|
84
|
+
environment,
|
|
85
|
+
});
|
|
86
|
+
if (applications.size >= MAXIMUM_CACHED_APPLICATIONS) {
|
|
87
|
+
const oldest = applications.keys().next().value;
|
|
88
|
+
if (oldest !== undefined) {
|
|
89
|
+
const evicted = applications.get(oldest);
|
|
90
|
+
applications.delete(oldest);
|
|
91
|
+
if (evicted !== undefined) {
|
|
92
|
+
try {
|
|
93
|
+
await closeEvictedApplication(evicted.application);
|
|
94
|
+
}
|
|
95
|
+
catch (cause) {
|
|
96
|
+
await serving
|
|
97
|
+
.close({ deadline: Date.now() + APPLICATION_CLOSE_TIMEOUT_MS })
|
|
98
|
+
.catch(() => undefined);
|
|
99
|
+
throw cause;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
applications.set(key, created);
|
|
105
|
+
return created;
|
|
106
|
+
};
|
|
107
|
+
return Object.freeze({
|
|
108
|
+
async fetch(request, bindings, executionContext) {
|
|
109
|
+
const requestUrl = new URL(request.url);
|
|
110
|
+
if (config.definition.frontend !== undefined) {
|
|
111
|
+
const asset = await frontendAsset(config.definition, bindings, requestUrl, request);
|
|
112
|
+
if (asset !== undefined)
|
|
113
|
+
return asset;
|
|
114
|
+
}
|
|
115
|
+
const publicUrl = canonicalServingUrl(config.resolveUrl?.(bindings, requestOrigin(requestUrl, request)) ??
|
|
116
|
+
bindings.WORKER_URL ??
|
|
117
|
+
requestOrigin(requestUrl, request));
|
|
118
|
+
const serving = await applicationFor(publicUrl, bindings);
|
|
119
|
+
return serving.application.app.fetch(request, serving.environment, executionContext);
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Close an evicted Application before its environment bindings leave the cache. */
|
|
125
|
+
export function closeEvictedApplication(application, now = Date.now) {
|
|
126
|
+
return application.close({ deadline: now() + APPLICATION_CLOSE_TIMEOUT_MS });
|
|
127
|
+
}
|
|
128
|
+
async function frontendAsset(definition, environment, url, request) {
|
|
129
|
+
const frontend = definition.frontend;
|
|
130
|
+
if (frontend === undefined || frontend.source.kind === 'external')
|
|
131
|
+
return undefined;
|
|
132
|
+
const routes = frontend.routes;
|
|
133
|
+
const route = Object.values(routes).find((candidate) => candidate.path === url.pathname);
|
|
134
|
+
const staticAsset = url.pathname.startsWith('/assets/');
|
|
135
|
+
if (route === undefined && !staticAsset)
|
|
136
|
+
return undefined;
|
|
137
|
+
if (request.method !== 'GET' && request.method !== 'HEAD')
|
|
138
|
+
return undefined;
|
|
139
|
+
const binding = environment.ASSETS;
|
|
140
|
+
if (binding === undefined)
|
|
141
|
+
return undefined;
|
|
142
|
+
const dev = environment.FRONTEND_DEV_URL?.replace(/\/+$/u, '');
|
|
143
|
+
if (dev !== undefined && dev.length > 0) {
|
|
144
|
+
return fetch(new Request(`${dev}${url.pathname}${url.search}`, request));
|
|
145
|
+
}
|
|
146
|
+
const path = route === undefined ? `${url.pathname}${url.search}` : `/${route.document}${url.search}`;
|
|
147
|
+
return binding.fetch(new Request(new URL(path, url.origin), request));
|
|
148
|
+
}
|
|
149
|
+
function requestOrigin(url, request) {
|
|
150
|
+
if (url.protocol !== 'http:')
|
|
151
|
+
return url.origin;
|
|
152
|
+
const forwarded = request.headers.get('x-forwarded-proto')?.split(',')[0]?.trim().toLowerCase();
|
|
153
|
+
return forwarded === 'https' ? `https://${url.host}` : url.origin;
|
|
154
|
+
}
|
|
155
|
+
function canonicalServingUrl(input) {
|
|
156
|
+
let url;
|
|
157
|
+
try {
|
|
158
|
+
url = new URL(input);
|
|
159
|
+
}
|
|
160
|
+
catch (cause) {
|
|
161
|
+
throw new TypeError('Cloudflare Worker serving URL is invalid.', { cause });
|
|
162
|
+
}
|
|
163
|
+
if ((url.protocol !== 'https:' && url.protocol !== 'http:') ||
|
|
164
|
+
url.username !== '' ||
|
|
165
|
+
url.password !== '' ||
|
|
166
|
+
url.pathname !== '/' ||
|
|
167
|
+
url.search !== '' ||
|
|
168
|
+
url.hash !== '') {
|
|
169
|
+
throw new TypeError('Cloudflare Worker serving URL must be one HTTP(S) origin.');
|
|
170
|
+
}
|
|
171
|
+
return url.origin;
|
|
172
|
+
}
|
|
173
|
+
function deploymentVersion(environment) {
|
|
174
|
+
const input = environment.ASTRALE_VERSION_METADATA;
|
|
175
|
+
if (input !== null &&
|
|
176
|
+
typeof input === 'object' &&
|
|
177
|
+
typeof input.id === 'string' &&
|
|
178
|
+
input.id.length > 0) {
|
|
179
|
+
return input.id;
|
|
180
|
+
}
|
|
181
|
+
const fallback = environment.ASTRALE_DEPLOYMENT_VERSION;
|
|
182
|
+
if (typeof fallback === 'string' && fallback.length > 0)
|
|
183
|
+
return fallback;
|
|
184
|
+
throw new TypeError('Cloudflare Worker deployment version is unavailable.');
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAChE,OAAO,EAAE,IAAI,IAAI,eAAe,EAAE,MAAM,MAAM,CAAA;AAE9C,MAAM,2BAA2B,GAAG,CAAC,CAAA;AACrC,MAAM,4BAA4B,GAAG,KAAK,CAAA;AA0D1C;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IAKnC,OAAO,UACL,MAA8D;QAE9D,MAAM,YAAY,GAAG,IAAI,GAAG,EAA0C,CAAA;QAEtE,MAAM,cAAc,GAAG,KAAK,EAC1B,GAAW,EACX,QAAkB,EACuB,EAAE;YAC3C,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;YAC3C,MAAM,GAAG,GAAG,GAAG,GAAG,SAAS,OAAO,EAAE,CAAA;YACpC,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACpC,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,MAAM,CAAA;YACvC,MAAM,WAAW,GACf,MAAM,CAAC,kBAAkB,KAAK,SAAS;gBACrC,CAAC,CAAE,QAAmC;gBACtC,CAAC,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;YAE/C,MAAM,WAAW,GAAiB,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;gBACtD,MAAM,OAAO,G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nB,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAsC;IAC/D,MAAM,KAAK,GAAG,WAAW,CAAC,wBAAwB,CAAA;IAClD,IACE,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ;QAC5B,KAAK,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,EACnB,CAAC;QACD,OAAO,KAAK,CAAC,EAAE,CAAA;IACjB,CAAC;IACD,MAAM,QAAQ,GAAG,WAAW,CAAC,0BAA0B,CAAA;IACvD,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAA;IACxE,MAAM,IAAI,SAAS,CAAC,sDAAsD,CAAC,CAAA;AAC7E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/adapter-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-beta.1",
|
|
4
4
|
"description": "Deploy an Astrale domain as a standalone Cloudflare Worker",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"dist",
|
|
16
16
|
"src",
|
|
17
17
|
"template",
|
|
18
|
+
"!template/node_modules",
|
|
18
19
|
"!template/pnpm-lock.yaml"
|
|
19
20
|
],
|
|
20
21
|
"type": "module",
|
|
@@ -26,14 +27,21 @@
|
|
|
26
27
|
"import": "./dist/index.js"
|
|
27
28
|
},
|
|
28
29
|
"./build": {
|
|
29
|
-
"types": "./dist/build.d.ts",
|
|
30
|
-
"import": "./dist/build.js"
|
|
30
|
+
"types": "./dist/build/index.d.ts",
|
|
31
|
+
"import": "./dist/build/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./worker": {
|
|
34
|
+
"types": "./dist/worker/index.d.ts",
|
|
35
|
+
"import": "./dist/worker/index.js"
|
|
31
36
|
},
|
|
32
37
|
"./package.json": "./package.json"
|
|
33
38
|
},
|
|
34
39
|
"dependencies": {
|
|
40
|
+
"@astrale-os/kernel-core": "0.9.0-beta.1",
|
|
41
|
+
"@astrale-os/kernel-dsl": "0.2.0-beta.1",
|
|
42
|
+
"hono": "^4.6.20",
|
|
35
43
|
"jose": "^6.1.3",
|
|
36
|
-
"@astrale-os/sdk": "^0.
|
|
44
|
+
"@astrale-os/sdk": "^0.5.0-beta.1"
|
|
37
45
|
},
|
|
38
46
|
"devDependencies": {
|
|
39
47
|
"@astrale-os/ox": ">=0.1.0 <1.0.0",
|
|
@@ -43,7 +51,7 @@
|
|
|
43
51
|
"oxlint": "latest",
|
|
44
52
|
"typescript": "~6.0.1-rc",
|
|
45
53
|
"vitest": "^3.0.0",
|
|
46
|
-
"wrangler": "4.
|
|
54
|
+
"wrangler": "4.121.0"
|
|
47
55
|
},
|
|
48
56
|
"engines": {
|
|
49
57
|
"node": ">=22"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Codegen for the Cloudflare module entry owned by the adapter. */
|
|
2
|
+
|
|
3
|
+
export interface WorkerCodegenOptions {
|
|
4
|
+
readonly origin: string
|
|
5
|
+
/** Optional same-zone routing service selected by the adapter environment. */
|
|
6
|
+
readonly router?: {
|
|
7
|
+
readonly binding: string
|
|
8
|
+
readonly hostSuffix: string
|
|
9
|
+
readonly minLabels: number
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function generateWorkerEntry(options: WorkerCodegenOptions): string {
|
|
14
|
+
const router = options.router
|
|
15
|
+
const routerPredicate =
|
|
16
|
+
router === undefined
|
|
17
|
+
? ''
|
|
18
|
+
: `
|
|
19
|
+
function isInstanceHost(host: string): boolean {
|
|
20
|
+
return host.endsWith('${router.hostSuffix}') && host.split('.').length >= ${router.minLabels}
|
|
21
|
+
}
|
|
22
|
+
`
|
|
23
|
+
const routeSubrequest =
|
|
24
|
+
router === undefined
|
|
25
|
+
? ''
|
|
26
|
+
: `
|
|
27
|
+
routeSubrequest: (url, env) => {
|
|
28
|
+
const labels = url.hostname.split('.')
|
|
29
|
+
if (env.DISPATCHER && labels[1] === 'svc') return env.DISPATCHER.get(labels[0]!)
|
|
30
|
+
if (env.${router.binding} && isInstanceHost(url.hostname)) return env.${router.binding}
|
|
31
|
+
return null
|
|
32
|
+
},`
|
|
33
|
+
|
|
34
|
+
return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
|
|
35
|
+
// Regenerated by every Astrale Domain build, dev, and deploy operation.
|
|
36
|
+
// Domain origin: ${options.origin}
|
|
37
|
+
import type { CloudflareAdapterBindings } from '@astrale-os/adapter-cloudflare/worker'
|
|
38
|
+
import type { ApplicationEnvironment } from '../implementation.js'
|
|
39
|
+
|
|
40
|
+
import { cloudflareWorkerEntry } from '@astrale-os/adapter-cloudflare/worker'
|
|
41
|
+
import { domain } from '../implementation.js'
|
|
42
|
+
import { PRIVATE_JWK } from './identity.js'
|
|
43
|
+
|
|
44
|
+
type WorkerEnv = CloudflareEnv & ApplicationEnvironment & CloudflareAdapterBindings
|
|
45
|
+
${routerPredicate}
|
|
46
|
+
export default cloudflareWorkerEntry<WorkerEnv>()({
|
|
47
|
+
definition: domain,
|
|
48
|
+
privateKey: PRIVATE_JWK,
|
|
49
|
+
resolveUrl: (env, requestOrigin) => env.WORKER_URL ?? requestOrigin,
|
|
50
|
+
selfBinding: (env) => env.SELF,${routeSubrequest}
|
|
51
|
+
})
|
|
52
|
+
`
|
|
53
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* internal adapter detail the dev never sees.
|
|
5
5
|
*
|
|
6
6
|
* `main` is `./worker.gen.ts` (same dir). `assets.directory` points at the
|
|
7
|
-
*
|
|
7
|
+
* adapter's materialized frontend stage. A `SELF` service binding enables autobinding
|
|
8
8
|
* (a handler calling back into its own domain). Custom-domain deploys attach a
|
|
9
9
|
* `custom_domain` route; otherwise the Worker ships to `*.workers.dev`.
|
|
10
10
|
*
|
|
@@ -12,15 +12,17 @@
|
|
|
12
12
|
* (extra bindings: KV, R2, D1, queues, …) — see `mergeUserConfig`.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import { deepMergeConfig } from './merge'
|
|
15
|
+
import { deepMergeConfig } from './merge.js'
|
|
17
16
|
|
|
18
17
|
export interface WranglerCodegenOptions {
|
|
19
18
|
workerName: string
|
|
20
19
|
/** Full custom hostname for a routed deploy (e.g. 'crm.acme.dev'). */
|
|
21
20
|
route?: string
|
|
22
|
-
/**
|
|
23
|
-
|
|
21
|
+
/** Exact materialized local frontend; absence means no ASSETS binding. */
|
|
22
|
+
frontend?: {
|
|
23
|
+
readonly directory: string
|
|
24
|
+
readonly routes: readonly string[]
|
|
25
|
+
}
|
|
24
26
|
/** Plain (non-secret) vars to bake in. */
|
|
25
27
|
vars?: Record<string, string>
|
|
26
28
|
/** Add the SELF service binding (autobinding). */
|
|
@@ -41,15 +43,17 @@ export interface WranglerCodegenOptions {
|
|
|
41
43
|
wrangler?: Record<string, unknown>
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
// Wrangler 4.121.0's pinned workerd accepts dates through 2026-08-11.
|
|
47
|
+
const COMPATIBILITY_DATE = '2026-08-11'
|
|
45
48
|
|
|
46
49
|
export function generateWranglerConfig(opts: WranglerCodegenOptions): string {
|
|
47
50
|
const config: Record<string, unknown> = {
|
|
48
51
|
name: opts.workerName,
|
|
49
52
|
main: './worker.gen.ts',
|
|
50
53
|
compatibility_date: COMPATIBILITY_DATE,
|
|
51
|
-
compatibility_flags: ['nodejs_compat'
|
|
54
|
+
compatibility_flags: ['nodejs_compat'],
|
|
52
55
|
workers_dev: true,
|
|
56
|
+
version_metadata: { binding: 'ASTRALE_VERSION_METADATA' },
|
|
53
57
|
observability: { enabled: true },
|
|
54
58
|
}
|
|
55
59
|
|
|
@@ -57,12 +61,23 @@ export function generateWranglerConfig(opts: WranglerCodegenOptions): string {
|
|
|
57
61
|
config.routes = [{ pattern: opts.route, custom_domain: true }]
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
if (opts.
|
|
64
|
+
if (opts.frontend !== undefined) {
|
|
61
65
|
config.assets = {
|
|
62
|
-
directory:
|
|
66
|
+
directory: opts.frontend.directory,
|
|
63
67
|
binding: 'ASSETS',
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
run_worker_first: [
|
|
69
|
+
'/invoke',
|
|
70
|
+
'/invoke/*',
|
|
71
|
+
'/install',
|
|
72
|
+
'/install/*',
|
|
73
|
+
'/health',
|
|
74
|
+
'/health/*',
|
|
75
|
+
'/meta',
|
|
76
|
+
'/meta/*',
|
|
77
|
+
'/.well-known',
|
|
78
|
+
'/.well-known/*',
|
|
79
|
+
...opts.frontend.routes,
|
|
80
|
+
],
|
|
66
81
|
}
|
|
67
82
|
}
|
|
68
83
|
|
|
@@ -82,7 +97,14 @@ export function generateWranglerConfig(opts: WranglerCodegenOptions): string {
|
|
|
82
97
|
}
|
|
83
98
|
|
|
84
99
|
/** Keys the adapter owns and won't let `params.wrangler` clobber. */
|
|
85
|
-
const ADAPTER_OWNED_KEYS = [
|
|
100
|
+
const ADAPTER_OWNED_KEYS = [
|
|
101
|
+
'name',
|
|
102
|
+
'main',
|
|
103
|
+
'assets',
|
|
104
|
+
'routes',
|
|
105
|
+
'compatibility_date',
|
|
106
|
+
'version_metadata',
|
|
107
|
+
]
|
|
86
108
|
|
|
87
109
|
/**
|
|
88
110
|
* Deep-merge the dev's raw wrangler overlay over the generated config, after
|