@cloudflare/vite-plugin 1.34.0 → 1.36.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.mjs +291 -256
- package/dist/index.mjs.map +1 -1
- package/dist/{package-dg3YhLY6.mjs → package-CY9M77Eh.mjs} +2 -2
- package/dist/{package-dg3YhLY6.mjs.map → package-CY9M77Eh.mjs.map} +1 -1
- package/dist/workers/asset-worker/index.js +16 -5
- package/dist/workers/router-worker/index.js +138 -107
- package/dist/workers/runner-worker/index.js +5 -4
- package/package.json +8 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@cloudflare/vite-plugin",
|
|
4
|
-
version: "1.
|
|
4
|
+
version: "1.36.0",
|
|
5
5
|
description: "Cloudflare plugin for Vite",
|
|
6
6
|
keywords: [
|
|
7
7
|
"cloudflare",
|
|
@@ -79,4 +79,4 @@ var package_default = {
|
|
|
79
79
|
|
|
80
80
|
//#endregion
|
|
81
81
|
export { package_default as default };
|
|
82
|
-
//# sourceMappingURL=package-
|
|
82
|
+
//# sourceMappingURL=package-CY9M77Eh.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-
|
|
1
|
+
{"version":3,"file":"package-CY9M77Eh.mjs","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@cloudflare/vite-plugin\",\n\t\"version\": \"1.36.0\",\n\t\"description\": \"Cloudflare plugin for Vite\",\n\t\"keywords\": [\n\t\t\"cloudflare\",\n\t\t\"cloudflare-workers\",\n\t\t\"vite\",\n\t\t\"vite-plugin\",\n\t\t\"workers\"\n\t],\n\t\"homepage\": \"https://github.com/cloudflare/workers-sdk/tree/main/packages/vite-plugin-cloudflare#readme\",\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/cloudflare/workers-sdk/issues\"\n\t},\n\t\"license\": \"MIT\",\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"https://github.com/cloudflare/workers-sdk.git\",\n\t\t\"directory\": \"packages/vite-plugin-cloudflare\"\n\t},\n\t\"files\": [\n\t\t\"dist\"\n\t],\n\t\"type\": \"module\",\n\t\"sideEffects\": false,\n\t\"main\": \"./dist/index.mjs\",\n\t\"types\": \"./dist/index.d.mts\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"types\": \"./dist/index.d.mts\",\n\t\t\t\"import\": \"./dist/index.mjs\"\n\t\t}\n\t},\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t},\n\t\"scripts\": {\n\t\t\"build\": \"tsdown\",\n\t\t\"check:type\": \"tsc --build\",\n\t\t\"dev\": \"tsdown --watch\",\n\t\t\"test\": \"vitest run\",\n\t\t\"test:ci\": \"pnpm test\",\n\t\t\"test:e2e\": \"vitest run -c e2e/vitest.config.ts\",\n\t\t\"test:watch\": \"vitest\"\n\t},\n\t\"dependencies\": {\n\t\t\"@cloudflare/unenv-preset\": \"workspace:*\",\n\t\t\"miniflare\": \"workspace:*\",\n\t\t\"unenv\": \"2.0.0-rc.24\",\n\t\t\"wrangler\": \"workspace:*\",\n\t\t\"ws\": \"catalog:default\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@cloudflare/containers-shared\": \"workspace:*\",\n\t\t\"@cloudflare/mock-npm-registry\": \"workspace:*\",\n\t\t\"@cloudflare/workers-shared\": \"workspace:*\",\n\t\t\"@cloudflare/workers-tsconfig\": \"workspace:*\",\n\t\t\"@cloudflare/workers-types\": \"catalog:default\",\n\t\t\"@cloudflare/workers-utils\": \"workspace:*\",\n\t\t\"@remix-run/node-fetch-server\": \"^0.8.0\",\n\t\t\"@types/node\": \"catalog:default\",\n\t\t\"@types/semver\": \"^7.5.1\",\n\t\t\"@types/ws\": \"^8.5.13\",\n\t\t\"defu\": \"^6.1.4\",\n\t\t\"get-port\": \"^7.1.0\",\n\t\t\"magic-string\": \"^0.30.12\",\n\t\t\"mlly\": \"^1.7.4\",\n\t\t\"open\": \"catalog:default\",\n\t\t\"picocolors\": \"^1.1.1\",\n\t\t\"semver\": \"^7.7.1\",\n\t\t\"tinyglobby\": \"catalog:default\",\n\t\t\"tree-kill\": \"catalog:default\",\n\t\t\"tsdown\": \"0.16.3\",\n\t\t\"typescript\": \"catalog:default\",\n\t\t\"vite\": \"catalog:default\",\n\t\t\"vite-legacy\": \"npm:vite@7.1.12\",\n\t\t\"vitest\": \"catalog:default\"\n\t},\n\t\"peerDependencies\": {\n\t\t\"vite\": \"^6.1.0 || ^7.0.0 || ^8.0.0\",\n\t\t\"wrangler\": \"workspace:^\"\n\t},\n\t\"workers-sdk\": {\n\t\t\"prerelease\": true\n\t}\n}\n"],"mappings":";sBAAA;OACS;UACG;cACI;WACH;EACX;EACA;EACA;EACA;EACA;EACA;WACW;OACJ,EACP,OAAO,oDACP;UACU;aACG;EACb,QAAQ;EACR,OAAO;EACP,aAAa;EACb;QACQ,CACR,OACA;OACO;cACO;OACP;QACC;UACE,EACV,KAAK;EACJ,SAAS;EACT,UAAU;EACV,EACD;gBACgB,EAChB,UAAU,UACV;UACU;EACV,SAAS;EACT,cAAc;EACd,OAAO;EACP,QAAQ;EACR,WAAW;EACX,YAAY;EACZ,cAAc;EACd;eACe;EACf,4BAA4B;EAC5B,aAAa;EACb,SAAS;EACT,YAAY;EACZ,MAAM;EACN;kBACkB;EAClB,iCAAiC;EACjC,iCAAiC;EACjC,8BAA8B;EAC9B,gCAAgC;EAChC,6BAA6B;EAC7B,6BAA6B;EAC7B,gCAAgC;EAChC,eAAe;EACf,iBAAiB;EACjB,aAAa;EACb,QAAQ;EACR,YAAY;EACZ,gBAAgB;EAChB,QAAQ;EACR,QAAQ;EACR,cAAc;EACd,UAAU;EACV,cAAc;EACd,aAAa;EACb,UAAU;EACV,cAAc;EACd,QAAQ;EACR,eAAe;EACf,UAAU;EACV;mBACmB;EACnB,QAAQ;EACR,YAAY;EACZ;CACD,eAAe,EACd,cAAc,MACd;CACD"}
|
|
@@ -4652,6 +4652,11 @@ function mockJaegerBinding() {
|
|
|
4652
4652
|
//#endregion
|
|
4653
4653
|
//#region ../workers-shared/asset-worker/src/analytics.ts
|
|
4654
4654
|
const VERSION$1 = 1;
|
|
4655
|
+
let EntrypointType = /* @__PURE__ */ function(EntrypointType$1) {
|
|
4656
|
+
EntrypointType$1[EntrypointType$1["Outer"] = 0] = "Outer";
|
|
4657
|
+
EntrypointType$1[EntrypointType$1["Inner"] = 1] = "Inner";
|
|
4658
|
+
return EntrypointType$1;
|
|
4659
|
+
}({});
|
|
4655
4660
|
const COMPATIBILITY_FLAG_MASKS = { assets_navigation_prefers_asset_serving: 1 };
|
|
4656
4661
|
var Analytics = class {
|
|
4657
4662
|
data = {};
|
|
@@ -4685,7 +4690,8 @@ var Analytics = class {
|
|
|
4685
4690
|
this.data.metalId ?? -1,
|
|
4686
4691
|
this.data.coloTier ?? -1,
|
|
4687
4692
|
this.data.status ?? -1,
|
|
4688
|
-
compatibilityFlagsBitmask
|
|
4693
|
+
compatibilityFlagsBitmask,
|
|
4694
|
+
this.data.entrypoint ?? -1
|
|
4689
4695
|
],
|
|
4690
4696
|
blobs: [
|
|
4691
4697
|
this.data.hostname?.substring(0, 256),
|
|
@@ -4695,7 +4701,8 @@ var Analytics = class {
|
|
|
4695
4701
|
this.data.error?.substring(0, 256),
|
|
4696
4702
|
this.data.version,
|
|
4697
4703
|
this.data.coloRegion,
|
|
4698
|
-
this.data.cacheStatus
|
|
4704
|
+
this.data.cacheStatus,
|
|
4705
|
+
this.data.cohort
|
|
4699
4706
|
]
|
|
4700
4707
|
});
|
|
4701
4708
|
}
|
|
@@ -4782,6 +4789,7 @@ function comparePathHashWithEntry(searchValue, manifest, entryIndex) {
|
|
|
4782
4789
|
for (let offset = 0; offset < PATH_HASH_SIZE; offset++, pathHashOffset++) {
|
|
4783
4790
|
const s = searchValue[offset];
|
|
4784
4791
|
const e = manifest[pathHashOffset];
|
|
4792
|
+
if (s === void 0 || e === void 0) throw new TypeError(`Unexpected undefined value at offset ${offset} during path hash comparison`);
|
|
4785
4793
|
if (s < e) return -1;
|
|
4786
4794
|
if (s > e) return 1;
|
|
4787
4795
|
}
|
|
@@ -5664,7 +5672,7 @@ async function unstableGetByPathnameImpl(env, exists, getByETag, pathname, reque
|
|
|
5664
5672
|
return getByETag(eTag, request);
|
|
5665
5673
|
});
|
|
5666
5674
|
}
|
|
5667
|
-
async function runFetchRequest(request, env, ctx, exists, getByETag) {
|
|
5675
|
+
async function runFetchRequest(request, env, ctx, exists, getByETag, cohort) {
|
|
5668
5676
|
let sentry;
|
|
5669
5677
|
const analytics = new Analytics(env.ANALYTICS);
|
|
5670
5678
|
const performance = new PerformanceTimer(env.UNSAFE_PERFORMANCE);
|
|
@@ -5692,7 +5700,9 @@ async function runFetchRequest(request, env, ctx, exists, getByETag) {
|
|
|
5692
5700
|
htmlHandling: config.html_handling,
|
|
5693
5701
|
notFoundHandling: config.not_found_handling,
|
|
5694
5702
|
compatibilityFlags: config.compatibility_flags,
|
|
5695
|
-
userAgent
|
|
5703
|
+
userAgent,
|
|
5704
|
+
entrypoint: EntrypointType.Inner,
|
|
5705
|
+
cohort: cohort ?? "unknown"
|
|
5696
5706
|
});
|
|
5697
5707
|
return await env.JAEGER.enterSpan("handleRequest", async (span) => {
|
|
5698
5708
|
span.setTags({
|
|
@@ -5715,7 +5725,8 @@ var AssetWorkerInner = class extends WorkerEntrypoint {
|
|
|
5715
5725
|
async fetch(request) {
|
|
5716
5726
|
this.env.JAEGER ??= mockJaegerBinding();
|
|
5717
5727
|
const traceContext = this.ctx.props?.traceContext ?? null;
|
|
5718
|
-
const
|
|
5728
|
+
const cohort = this.ctx.version?.cohort;
|
|
5729
|
+
const response = await this.env.JAEGER.runWithSpanContext(traceContext, () => runFetchRequest(request, this.env, this.ctx, this.unstable_exists.bind(this), this.unstable_getByETag.bind(this), cohort));
|
|
5719
5730
|
if (response instanceof Response) return response;
|
|
5720
5731
|
throw new Error("AssetWorkerInner fetch returned non-Response value.");
|
|
5721
5732
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
2
|
+
|
|
1
3
|
//#region ../workers-shared/utils/responses.ts
|
|
2
4
|
var TemporaryRedirectResponse = class TemporaryRedirectResponse extends Response {
|
|
3
5
|
static status = 307;
|
|
@@ -6240,126 +6242,155 @@ function renderLimitedResponse(req) {
|
|
|
6240
6242
|
//#endregion
|
|
6241
6243
|
//#region ../workers-shared/router-worker/src/worker.ts
|
|
6242
6244
|
var worker_default = { async fetch(request, env, ctx) {
|
|
6243
|
-
|
|
6244
|
-
let userWorkerInvocation = false;
|
|
6245
|
+
const loopbackCtx = ctx;
|
|
6245
6246
|
const analytics = new Analytics(env.ANALYTICS);
|
|
6246
|
-
|
|
6247
|
-
const startTimeMs = performance.now();
|
|
6247
|
+
let inner;
|
|
6248
6248
|
try {
|
|
6249
|
-
if (
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
coloRegion: env.COLO_METADATA.coloRegion,
|
|
6262
|
-
hostname: url.hostname,
|
|
6263
|
-
version: env.VERSION_METADATA.tag,
|
|
6264
|
-
userWorkerAhead: config.invoke_user_worker_ahead_of_assets
|
|
6265
|
-
});
|
|
6266
|
-
if (url.pathname.startsWith("/cdn-cgi/") && request.url.includes("/cdn-cgi\\")) {
|
|
6267
|
-
analytics.setData({ cdnCgiBackslashBypassUrl: request.url });
|
|
6268
|
-
return new TemporaryRedirectResponse(url.href);
|
|
6249
|
+
if (env.COLO_METADATA && env.VERSION_METADATA && env.CONFIG) {
|
|
6250
|
+
const url = new URL(request.url);
|
|
6251
|
+
analytics.setData({
|
|
6252
|
+
accountId: env.CONFIG.account_id,
|
|
6253
|
+
scriptId: env.CONFIG.script_id,
|
|
6254
|
+
coloId: env.COLO_METADATA.coloId,
|
|
6255
|
+
metalId: env.COLO_METADATA.metalId,
|
|
6256
|
+
coloTier: env.COLO_METADATA.coloTier,
|
|
6257
|
+
coloRegion: env.COLO_METADATA.coloRegion,
|
|
6258
|
+
hostname: url.hostname,
|
|
6259
|
+
version: env.VERSION_METADATA.tag
|
|
6260
|
+
});
|
|
6269
6261
|
}
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6262
|
+
inner = loopbackCtx.exports.RouterInnerEntrypoint({ props: {} });
|
|
6263
|
+
} catch (err) {
|
|
6264
|
+
setupSentry(request, ctx, env.SENTRY_DSN, env.SENTRY_ACCESS_CLIENT_ID, env.SENTRY_ACCESS_CLIENT_SECRET, env.COLO_METADATA, env.VERSION_METADATA, env.CONFIG?.account_id, env.CONFIG?.script_id)?.captureException(err);
|
|
6265
|
+
if (err instanceof Error) analytics.setData({ error: err.message });
|
|
6266
|
+
analytics.write();
|
|
6267
|
+
throw err;
|
|
6268
|
+
}
|
|
6269
|
+
return inner.fetch(request);
|
|
6270
|
+
} };
|
|
6271
|
+
var RouterInnerEntrypoint = class extends WorkerEntrypoint {
|
|
6272
|
+
async fetch(request) {
|
|
6273
|
+
let sentry;
|
|
6274
|
+
let userWorkerInvocation = false;
|
|
6275
|
+
const analytics = new Analytics(this.env.ANALYTICS);
|
|
6276
|
+
const performance = new PerformanceTimer(this.env.UNSAFE_PERFORMANCE);
|
|
6277
|
+
const startTimeMs = performance.now();
|
|
6278
|
+
try {
|
|
6279
|
+
if (!this.env.JAEGER) this.env.JAEGER = mockJaegerBinding();
|
|
6280
|
+
sentry = setupSentry(request, this.ctx, this.env.SENTRY_DSN, this.env.SENTRY_ACCESS_CLIENT_ID, this.env.SENTRY_ACCESS_CLIENT_SECRET, this.env.COLO_METADATA, this.env.VERSION_METADATA, this.env.CONFIG?.account_id, this.env.CONFIG?.script_id);
|
|
6281
|
+
const hasStaticRouting = this.env.CONFIG.static_routing !== void 0;
|
|
6282
|
+
const config = applyRouterConfigDefaults(this.env.CONFIG);
|
|
6283
|
+
const eyeballConfig = applyEyeballConfigDefaults(this.env.EYEBALL_CONFIG);
|
|
6284
|
+
const url = new URL(request.url);
|
|
6285
|
+
if (this.env.COLO_METADATA && this.env.VERSION_METADATA && this.env.CONFIG) analytics.setData({
|
|
6286
|
+
accountId: this.env.CONFIG.account_id,
|
|
6287
|
+
scriptId: this.env.CONFIG.script_id,
|
|
6288
|
+
coloId: this.env.COLO_METADATA.coloId,
|
|
6289
|
+
metalId: this.env.COLO_METADATA.metalId,
|
|
6290
|
+
coloTier: this.env.COLO_METADATA.coloTier,
|
|
6291
|
+
coloRegion: this.env.COLO_METADATA.coloRegion,
|
|
6292
|
+
hostname: url.hostname,
|
|
6293
|
+
version: this.env.VERSION_METADATA.tag,
|
|
6294
|
+
userWorkerAhead: config.invoke_user_worker_ahead_of_assets
|
|
6295
|
+
});
|
|
6296
|
+
if (url.pathname.startsWith("/cdn-cgi/") && request.url.includes("/cdn-cgi\\")) {
|
|
6297
|
+
analytics.setData({ cdnCgiBackslashBypassUrl: request.url });
|
|
6298
|
+
return new TemporaryRedirectResponse(url.href);
|
|
6278
6299
|
}
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6300
|
+
const routeToUserWorker = async ({ asset }) => {
|
|
6301
|
+
if (!config.has_user_worker) throw new Error("Fetch for user worker without having a user worker binding");
|
|
6302
|
+
if (eyeballConfig.limitedAssetsOnly) {
|
|
6303
|
+
analytics.setData({ userWorkerFreeTierLimiting: true });
|
|
6304
|
+
return new Response(renderLimitedResponse(request), {
|
|
6305
|
+
status: 429,
|
|
6306
|
+
headers: { "Content-Type": "text/html" }
|
|
6307
|
+
});
|
|
6308
|
+
}
|
|
6309
|
+
analytics.setData({ dispatchtype: DISPATCH_TYPE.WORKER });
|
|
6310
|
+
userWorkerInvocation = true;
|
|
6311
|
+
return this.env.JAEGER.enterSpan("dispatch_worker", async (span) => {
|
|
6312
|
+
span.setTags({
|
|
6313
|
+
hasUserWorker: true,
|
|
6314
|
+
asset,
|
|
6315
|
+
dispatchType: DISPATCH_TYPE.WORKER
|
|
6316
|
+
});
|
|
6317
|
+
let shouldCheckContentType = false;
|
|
6318
|
+
if (url.pathname.endsWith("/_next/image")) {
|
|
6319
|
+
const queryURLParam = url.searchParams.get("url");
|
|
6320
|
+
if (queryURLParam && !queryURLParam.startsWith("/")) {
|
|
6321
|
+
if (request.method !== "GET" || request.headers.get("sec-fetch-dest") !== "image") {
|
|
6322
|
+
shouldCheckContentType = true;
|
|
6323
|
+
analytics.setData({ abuseMitigationURLHost: queryURLParam });
|
|
6324
|
+
}
|
|
6294
6325
|
}
|
|
6295
6326
|
}
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
|
|
6327
|
+
if (url.pathname === "/_image") {
|
|
6328
|
+
const hrefParam = url.searchParams.get("href");
|
|
6329
|
+
if (hrefParam && hrefParam.length > 2 && hrefParam.startsWith("//")) try {
|
|
6330
|
+
const hrefUrl = new URL("https:" + hrefParam);
|
|
6331
|
+
const isImageFetchDest = request.headers.get("sec-fetch-dest") == "image";
|
|
6332
|
+
if (hrefUrl.hostname !== url.hostname && !isImageFetchDest) {
|
|
6333
|
+
analytics.setData({ xssDetectionImageHref: hrefParam });
|
|
6334
|
+
return new Response("Blocked", { status: 403 });
|
|
6335
|
+
}
|
|
6336
|
+
} catch {
|
|
6337
|
+
console.log(`Invalid href parameter in /_image: ${hrefParam}`);
|
|
6338
|
+
}
|
|
6339
|
+
}
|
|
6340
|
+
analytics.setData({ timeToDispatch: performance.now() - startTimeMs });
|
|
6341
|
+
if (shouldCheckContentType) {
|
|
6342
|
+
const response = await this.env.USER_WORKER.fetch(request);
|
|
6343
|
+
if (response.status !== 304 && shouldBlockContentType(response)) {
|
|
6344
|
+
analytics.setData({ abuseMitigationBlocked: true });
|
|
6304
6345
|
return new Response("Blocked", { status: 403 });
|
|
6305
6346
|
}
|
|
6306
|
-
|
|
6307
|
-
console.log(`Invalid href parameter in /_image: ${hrefParam}`);
|
|
6347
|
+
return response;
|
|
6308
6348
|
}
|
|
6349
|
+
return this.env.USER_WORKER.fetch(request);
|
|
6350
|
+
});
|
|
6351
|
+
};
|
|
6352
|
+
const routeToAssets = async ({ asset }) => {
|
|
6353
|
+
analytics.setData({ dispatchtype: DISPATCH_TYPE.ASSETS });
|
|
6354
|
+
return await this.env.JAEGER.enterSpan("dispatch_assets", async (span) => {
|
|
6355
|
+
span.setTags({
|
|
6356
|
+
hasUserWorker: config.has_user_worker,
|
|
6357
|
+
asset,
|
|
6358
|
+
dispatchType: DISPATCH_TYPE.ASSETS
|
|
6359
|
+
});
|
|
6360
|
+
analytics.setData({ timeToDispatch: performance.now() - startTimeMs });
|
|
6361
|
+
return this.env.ASSET_WORKER.fetch(request);
|
|
6362
|
+
});
|
|
6363
|
+
};
|
|
6364
|
+
if (config.static_routing) {
|
|
6365
|
+
if (generateStaticRoutingRuleMatcher(config.static_routing.asset_worker ?? [])({ request })) {
|
|
6366
|
+
analytics.setData({ staticRoutingDecision: STATIC_ROUTING_DECISION.ROUTED });
|
|
6367
|
+
return await routeToAssets({ asset: "static_routing" });
|
|
6309
6368
|
}
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
analytics.setData({ abuseMitigationBlocked: true });
|
|
6315
|
-
return new Response("Blocked", { status: 403 });
|
|
6316
|
-
}
|
|
6317
|
-
return response;
|
|
6369
|
+
if (generateStaticRoutingRuleMatcher(config.static_routing.user_worker ?? [])({ request })) {
|
|
6370
|
+
if (!config.has_user_worker) throw new Error("Fetch for user worker without having a user worker binding");
|
|
6371
|
+
analytics.setData({ staticRoutingDecision: STATIC_ROUTING_DECISION.ROUTED });
|
|
6372
|
+
return await routeToUserWorker({ asset: "static_routing" });
|
|
6318
6373
|
}
|
|
6319
|
-
|
|
6320
|
-
});
|
|
6321
|
-
};
|
|
6322
|
-
const routeToAssets = async ({ asset }) => {
|
|
6323
|
-
analytics.setData({ dispatchtype: DISPATCH_TYPE.ASSETS });
|
|
6324
|
-
return await env.JAEGER.enterSpan("dispatch_assets", async (span) => {
|
|
6325
|
-
span.setTags({
|
|
6326
|
-
hasUserWorker: config.has_user_worker,
|
|
6327
|
-
asset,
|
|
6328
|
-
dispatchType: DISPATCH_TYPE.ASSETS
|
|
6329
|
-
});
|
|
6330
|
-
analytics.setData({ timeToDispatch: performance.now() - startTimeMs });
|
|
6331
|
-
return env.ASSET_WORKER.fetch(request);
|
|
6332
|
-
});
|
|
6333
|
-
};
|
|
6334
|
-
if (config.static_routing) {
|
|
6335
|
-
if (generateStaticRoutingRuleMatcher(config.static_routing.asset_worker ?? [])({ request })) {
|
|
6336
|
-
analytics.setData({ staticRoutingDecision: STATIC_ROUTING_DECISION.ROUTED });
|
|
6337
|
-
return await routeToAssets({ asset: "static_routing" });
|
|
6338
|
-
}
|
|
6339
|
-
if (generateStaticRoutingRuleMatcher(config.static_routing.user_worker ?? [])({ request })) {
|
|
6340
|
-
if (!config.has_user_worker) throw new Error("Fetch for user worker without having a user worker binding");
|
|
6341
|
-
analytics.setData({ staticRoutingDecision: STATIC_ROUTING_DECISION.ROUTED });
|
|
6342
|
-
return await routeToUserWorker({ asset: "static_routing" });
|
|
6374
|
+
analytics.setData({ staticRoutingDecision: hasStaticRouting ? STATIC_ROUTING_DECISION.NOT_ROUTED : STATIC_ROUTING_DECISION.NOT_PROVIDED });
|
|
6343
6375
|
}
|
|
6344
|
-
|
|
6376
|
+
if (config.invoke_user_worker_ahead_of_assets) return await routeToUserWorker({ asset: "static_routing" });
|
|
6377
|
+
const assetsExist = await this.env.ASSET_WORKER.unstable_canFetch(new Request(request.url, {
|
|
6378
|
+
headers: request.headers,
|
|
6379
|
+
method: request.method
|
|
6380
|
+
}));
|
|
6381
|
+
if (config.has_user_worker && !assetsExist) return await routeToUserWorker({ asset: "none" });
|
|
6382
|
+
return await routeToAssets({ asset: assetsExist ? "found" : "none" });
|
|
6383
|
+
} catch (err) {
|
|
6384
|
+
if (userWorkerInvocation) throw err;
|
|
6385
|
+
else if (err instanceof Error) analytics.setData({ error: err.message });
|
|
6386
|
+
if (sentry) sentry.captureException(err);
|
|
6387
|
+
throw err;
|
|
6388
|
+
} finally {
|
|
6389
|
+
analytics.setData({ requestTime: performance.now() - startTimeMs });
|
|
6390
|
+
analytics.write();
|
|
6345
6391
|
}
|
|
6346
|
-
if (config.invoke_user_worker_ahead_of_assets) return await routeToUserWorker({ asset: "static_routing" });
|
|
6347
|
-
const assetsExist = await env.ASSET_WORKER.unstable_canFetch(new Request(request.url, {
|
|
6348
|
-
headers: request.headers,
|
|
6349
|
-
method: request.method
|
|
6350
|
-
}));
|
|
6351
|
-
if (config.has_user_worker && !assetsExist) return await routeToUserWorker({ asset: "none" });
|
|
6352
|
-
return await routeToAssets({ asset: assetsExist ? "found" : "none" });
|
|
6353
|
-
} catch (err) {
|
|
6354
|
-
if (userWorkerInvocation) throw err;
|
|
6355
|
-
else if (err instanceof Error) analytics.setData({ error: err.message });
|
|
6356
|
-
if (sentry) sentry.captureException(err);
|
|
6357
|
-
throw err;
|
|
6358
|
-
} finally {
|
|
6359
|
-
analytics.setData({ requestTime: performance.now() - startTimeMs });
|
|
6360
|
-
analytics.write();
|
|
6361
6392
|
}
|
|
6362
|
-
}
|
|
6393
|
+
};
|
|
6363
6394
|
/**
|
|
6364
6395
|
* Check if the Content Type is allowed for the the `_next/image` endpoint.
|
|
6365
6396
|
*
|
|
@@ -6377,4 +6408,4 @@ function shouldBlockContentType(response) {
|
|
|
6377
6408
|
}
|
|
6378
6409
|
|
|
6379
6410
|
//#endregion
|
|
6380
|
-
export { worker_default as default };
|
|
6411
|
+
export { RouterInnerEntrypoint, worker_default as default };
|
|
@@ -32,11 +32,12 @@ function stripInternalEnv(internalEnv) {
|
|
|
32
32
|
* Copied from `packages/wrangler/templates/middleware/middleware-miniflare3-json-error.ts`
|
|
33
33
|
*/
|
|
34
34
|
function reduceError(e) {
|
|
35
|
+
const errorObj = e ?? {};
|
|
35
36
|
return {
|
|
36
|
-
name:
|
|
37
|
-
message:
|
|
38
|
-
stack:
|
|
39
|
-
cause:
|
|
37
|
+
name: errorObj.name,
|
|
38
|
+
message: errorObj.message ?? String(e),
|
|
39
|
+
stack: errorObj.stack,
|
|
40
|
+
cause: errorObj.cause === void 0 ? void 0 : reduceError(errorObj.cause)
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.0",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"unenv": "2.0.0-rc.24",
|
|
40
40
|
"ws": "8.18.0",
|
|
41
41
|
"@cloudflare/unenv-preset": "2.16.1",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
42
|
+
"miniflare": "4.20260504.0",
|
|
43
|
+
"wrangler": "4.88.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@cloudflare/workers-types": "^4.
|
|
46
|
+
"@cloudflare/workers-types": "^4.20260504.1",
|
|
47
47
|
"@remix-run/node-fetch-server": "^0.8.0",
|
|
48
48
|
"@types/node": "^22.10.1",
|
|
49
49
|
"@types/semver": "^7.5.1",
|
|
@@ -63,14 +63,14 @@
|
|
|
63
63
|
"vite-legacy": "npm:vite@7.1.12",
|
|
64
64
|
"vitest": "4.1.0",
|
|
65
65
|
"@cloudflare/containers-shared": "0.14.1",
|
|
66
|
+
"@cloudflare/workers-shared": "0.19.5",
|
|
66
67
|
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
67
|
-
"@cloudflare/workers-
|
|
68
|
-
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
69
|
-
"@cloudflare/workers-utils": "0.18.0"
|
|
68
|
+
"@cloudflare/workers-utils": "0.19.0",
|
|
69
|
+
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"vite": "^6.1.0 || ^7.0.0 || ^8.0.0",
|
|
73
|
-
"wrangler": "^4.
|
|
73
|
+
"wrangler": "^4.88.0"
|
|
74
74
|
},
|
|
75
75
|
"workers-sdk": {
|
|
76
76
|
"prerelease": true
|