@astrale-os/adapter-cloudflare 0.5.0-beta.12 → 0.5.0-beta.13
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/wrangler.d.ts +1 -0
- package/dist/build/codegen/wrangler.d.ts.map +1 -1
- package/dist/build/codegen/wrangler.js +13 -11
- package/dist/build/codegen/wrangler.js.map +1 -1
- package/dist/build/frontend.d.ts +13 -12
- package/dist/build/frontend.d.ts.map +1 -1
- package/dist/build/frontend.js +120 -131
- package/dist/build/frontend.js.map +1 -1
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.d.ts.map +1 -1
- package/dist/build/index.js +1 -1
- package/dist/build/index.js.map +1 -1
- package/dist/build/prepare.d.ts +1 -1
- package/dist/build/prepare.d.ts.map +1 -1
- package/dist/build/prepare.js +26 -5
- package/dist/build/prepare.js.map +1 -1
- package/dist/cloudflare.d.ts +2 -2
- package/dist/cloudflare.d.ts.map +1 -1
- package/dist/cloudflare.js +31 -37
- package/dist/cloudflare.js.map +1 -1
- package/dist/worker/index.js +21 -9
- package/dist/worker/index.js.map +1 -1
- package/package.json +2 -2
- package/src/build/codegen/wrangler.ts +14 -11
- package/src/build/frontend.ts +147 -173
- package/src/build/index.ts +4 -4
- package/src/build/prepare.ts +34 -6
- package/src/cloudflare.ts +42 -38
- package/src/worker/index.ts +24 -9
package/src/worker/index.ts
CHANGED
|
@@ -259,20 +259,35 @@ async function frontendAsset<S extends schema.DomainSchema>(
|
|
|
259
259
|
): Promise<Response | undefined> {
|
|
260
260
|
const frontend = definition.frontend
|
|
261
261
|
if (frontend === undefined || frontend.source.kind === 'external') return undefined
|
|
262
|
+
if (isReservedServicePath(url.pathname)) return undefined
|
|
263
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') return undefined
|
|
264
|
+
const dev = environment.FRONTEND_DEV_URL?.replace(/\/+$/u, '')
|
|
265
|
+
if (dev !== undefined && dev.length > 0) {
|
|
266
|
+
return fetch(new Request(new URL(`${url.pathname}${url.search}`, `${dev}/`), request))
|
|
267
|
+
}
|
|
262
268
|
const routes = frontend.routes as Readonly<Record<string, FrontendRoute>>
|
|
263
|
-
const
|
|
269
|
+
const spa = frontend.source.kind === 'vite' && frontend.source.spa
|
|
270
|
+
const route = Object.values(routes)
|
|
271
|
+
.filter(
|
|
272
|
+
(candidate) =>
|
|
273
|
+
candidate.path === url.pathname ||
|
|
274
|
+
(spa && (candidate.path === '/' || url.pathname.startsWith(`${candidate.path}/`))),
|
|
275
|
+
)
|
|
276
|
+
.sort((left, right) => right.path.length - left.path.length)[0]
|
|
264
277
|
const staticAsset = url.pathname.startsWith('/assets/')
|
|
265
278
|
if (route === undefined && !staticAsset) return undefined
|
|
266
|
-
if (request.method !== 'GET' && request.method !== 'HEAD') return undefined
|
|
267
279
|
const binding = environment.ASSETS
|
|
268
280
|
if (binding === undefined) return undefined
|
|
269
|
-
const
|
|
270
|
-
if (
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
281
|
+
const asset = await binding.fetch(request)
|
|
282
|
+
if (asset.status !== 404 || route === undefined) return asset
|
|
283
|
+
await asset.body?.cancel()
|
|
284
|
+
return binding.fetch(new Request(new URL(`/${route.document}${url.search}`, url.origin), request))
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function isReservedServicePath(path: string): boolean {
|
|
288
|
+
return ['/invoke', '/install', '/health', '/meta', '/.well-known'].some(
|
|
289
|
+
(reserved) => path === reserved || path.startsWith(`${reserved}/`),
|
|
290
|
+
)
|
|
276
291
|
}
|
|
277
292
|
|
|
278
293
|
function requestOrigin(url: URL, request: Request): string {
|