Skip to content

Commit

Permalink
Provides support for run_worker_first option
Browse files Browse the repository at this point in the history
- Warning for sunsetting of experimental_serve_directly
- Error for using run_worker_first and experimental_serve_directly together
- Sends run_worker_first field to EWC (in production) instead of old `serve_directly`
  • Loading branch information
WillTaylorDev committed Jan 24, 2025
1 parent fd5a455 commit a8d90e9
Show file tree
Hide file tree
Showing 23 changed files with 322 additions and 62 deletions.
2 changes: 1 addition & 1 deletion fixtures/asset-config/html-handling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe.each(testSuites)("$title", ({ title, suite }) => {
return {
html_handling,
not_found_handling: "none",
serve_directly: true,
run_worker_first: true,
};
});
});
Expand Down
2 changes: 1 addition & 1 deletion fixtures/asset-config/redirects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("[Asset Worker] `test location rewrite`", () => {
return {
html_handling: "none",
not_found_handling: "none",
serve_directly: true,
run_worker_first: true,
};
});
});
Expand Down
2 changes: 1 addition & 1 deletion fixtures/asset-config/url-normalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("[Asset Worker] `test slash normalization`", () => {
return {
html_handling: "none",
not_found_handling: "none",
serve_directly: true,
run_worker_first: true,
};
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fetch } from "undici";
import { afterAll, beforeAll, describe, it } from "vitest";
import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived";

describe("[Workers + Assets] serve_directly false", () => {
describe("[Workers + Assets] run_worker_first true", () => {
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined;

beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ compatibility_date = "2024-01-01"
[assets]
directory = "./public"
binding="ASSETS"
experimental_serve_directly = false
run_worker_first = true
1 change: 1 addition & 0 deletions fixtures/workers-with-assets/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ compatibility_date = "2024-01-01"
[assets]
directory = "./public"
binding="ASSETS"
experimental_serve_directly = true
12 changes: 11 additions & 1 deletion packages/workers-shared/asset-worker/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ import type { AssetConfig } from "../../utils/types";
export const applyConfigurationDefaults = (
configuration?: AssetConfig
): Required<AssetConfig> => {
let runWorkerFirst = undefined;
if (configuration?.run_worker_first !== undefined) {
runWorkerFirst = configuration?.run_worker_first;
} else if (configuration?.serve_directly !== undefined) {
runWorkerFirst = !configuration.serve_directly;
} else {
runWorkerFirst = false;
}

return {
html_handling: configuration?.html_handling ?? "auto-trailing-slash",
not_found_handling: configuration?.not_found_handling ?? "none",
serve_directly: configuration?.serve_directly ?? true,
run_worker_first: runWorkerFirst,
serve_directly: !runWorkerFirst,
};
};
5 changes: 5 additions & 0 deletions packages/workers-shared/asset-worker/tests/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("[Asset Worker] `handleRequest`", () => {
const configuration: Required<AssetConfig> = {
html_handling: "none",
not_found_handling: "none",
run_worker_first: false,
serve_directly: true,
};
const eTag = "some-etag";
Expand Down Expand Up @@ -38,6 +39,7 @@ describe("[Asset Worker] `handleRequest`", () => {
const configuration: Required<AssetConfig> = {
html_handling: "none",
not_found_handling: "none",
run_worker_first: false,
serve_directly: true,
};
const eTag = "some-etag";
Expand Down Expand Up @@ -69,6 +71,7 @@ describe("[Asset Worker] `handleRequest`", () => {
const configuration: Required<AssetConfig> = {
html_handling: "none",
not_found_handling: "none",
run_worker_first: false,
serve_directly: true,
};
const eTag = "some-etag";
Expand Down Expand Up @@ -100,6 +103,7 @@ describe("[Asset Worker] `handleRequest`", () => {
const configuration: Required<AssetConfig> = {
html_handling: "none",
not_found_handling: "none",
run_worker_first: false,
serve_directly: true,
};
const eTag = "some-etag";
Expand Down Expand Up @@ -192,6 +196,7 @@ describe("[Asset Worker] `handleRequest`", () => {
const configuration: Required<AssetConfig> = {
html_handling: "drop-trailing-slash",
not_found_handling: "none",
run_worker_first: false,
serve_directly: true,
};

Expand Down
1 change: 1 addition & 0 deletions packages/workers-shared/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const AssetConfigSchema = z.object({
.enum(["single-page-application", "404-page", "none"])
.optional(),
serve_directly: z.boolean().optional(),
run_worker_first: z.boolean().optional(),
});

export const InternalConfigSchema = z.object({
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/e2e/deployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
);
expect(text).toContain("<h1>404.html</h1>");
});
it("runs user worker ahead of matching assets when serve_directly = false", async () => {
it("runs user worker ahead of matching assets when run_worker_first = true", async () => {
await helper.seed({
"wrangler.toml": dedent`
name = "${workerName}"
Expand All @@ -501,7 +501,7 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
binding = "ASSETS"
html_handling = "none"
not_found_handling = "404-page"
experimental_serve_directly = false
run_worker_first = true
`,
"src/index.ts": dedent`
export default {
Expand Down
Loading

0 comments on commit a8d90e9

Please sign in to comment.