Skip to content

Commit aba0e9c

Browse files
authored
Workers Assets metafiles in asset-worker (#8279)
* Tidy up response status codes * Update tsconfig for workers-shared * Move rules engine to workers-shared * Run asset-worker tests in workerd * Refactor asset-worker in preparation of metafiles * Headers support in asset-worker * Redirects support in asset-worker * Add changeset for headers and redirects in asset-worker * PR feedback
1 parent 2044893 commit aba0e9c

File tree

25 files changed

+1403
-143
lines changed

25 files changed

+1403
-143
lines changed

.changeset/wild-mails-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/workers-shared": minor
3+
---
4+
5+
Add support for custom headers and redirects in asset-worker

fixtures/asset-config/html-handling.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const existsMock = (fileList: Set<string>) => {
1717
if (fileList.has(pathname)) {
1818
return pathname;
1919
}
20+
return null;
2021
}
2122
);
2223
};

fixtures/asset-config/redirects.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const existsMock = (fileList: Set<string>) => {
1515
if (fileList.has(pathname)) {
1616
return pathname;
1717
}
18+
return null;
1819
}
1920
);
2021
};
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
{
2+
"extends": "@cloudflare/workers-tsconfig/tsconfig.json",
23
"compilerOptions": {
3-
"target": "ES2020",
4-
"module": "ES2020",
5-
"lib": ["ES2020"],
64
"types": [
75
"@cloudflare/workers-types/experimental",
86
"@cloudflare/vitest-pool-workers"
97
],
10-
"moduleResolution": "bundler",
11-
"noEmit": true,
12-
"skipLibCheck": true
8+
"moduleResolution": "bundler"
139
},
1410
"include": ["**/*.ts"]
1511
}

fixtures/asset-config/url-normalization.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const existsMock = (fileList: Set<string>) => {
1515
if (fileList.has(pathname)) {
1616
return pathname;
1717
}
18+
return null;
1819
}
1920
);
2021
};

packages/pages-shared/asset-server/handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
generateRulesMatcher,
3+
replacer,
4+
} from "@cloudflare/workers-shared/asset-worker/src/utils/rules-engine";
15
import {
26
FoundResponse,
37
InternalServerErrorResponse,
@@ -11,7 +15,6 @@ import {
1115
SeeOtherResponse,
1216
TemporaryRedirectResponse,
1317
} from "./responses";
14-
import { generateRulesMatcher, replacer } from "./rulesEngine";
1518
import type {
1619
Metadata,
1720
MetadataHeadersEntries,

packages/pages-shared/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"test:ci": "vitest run"
2020
},
2121
"dependencies": {
22+
"@cloudflare/workers-shared": "workspace:*",
2223
"miniflare": "workspace:*"
2324
},
2425
"devDependencies": {

packages/workers-shared/asset-worker/src/configuration.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ export const applyConfigurationDefaults = (
88
compatibility_flags: configuration?.compatibility_flags ?? [],
99
html_handling: configuration?.html_handling ?? "auto-trailing-slash",
1010
not_found_handling: configuration?.not_found_handling ?? "none",
11+
redirects: configuration?.redirects ?? {
12+
version: 1,
13+
staticRules: {},
14+
rules: {},
15+
},
16+
headers: configuration?.headers ?? {
17+
version: 2,
18+
rules: {},
19+
},
1120
account_id: configuration?.account_id ?? -1,
1221
script_id: configuration?.script_id ?? -1,
1322
};

0 commit comments

Comments
 (0)