diff --git a/.yarn/cache/@types-node-npm-18.18.9-db29fe3223-629ce20357.zip b/.yarn/cache/@types-node-npm-18.18.9-db29fe3223-629ce20357.zip deleted file mode 100644 index e7ad1bc9..00000000 Binary files a/.yarn/cache/@types-node-npm-18.18.9-db29fe3223-629ce20357.zip and /dev/null differ diff --git a/.yarn/cache/undici-types-npm-5.26.5-de4f7c7bb9-3192ef6f3f.zip b/.yarn/cache/undici-types-npm-5.26.5-de4f7c7bb9-3192ef6f3f.zip deleted file mode 100644 index 6ab5ae67..00000000 Binary files a/.yarn/cache/undici-types-npm-5.26.5-de4f7c7bb9-3192ef6f3f.zip and /dev/null differ diff --git a/__tests__/__utils__/test-environment.ts b/__tests__/__utils__/test-environment.ts index cd47f52a..52959d96 100644 --- a/__tests__/__utils__/test-environment.ts +++ b/__tests__/__utils__/test-environment.ts @@ -1,3 +1,4 @@ +import { CfProperties } from '@cloudflare/workers-types' import TOML from '@iarna/toml' import fs from 'fs' import path from 'path' @@ -63,8 +64,8 @@ export abstract class TestEnvironment { public abstract fetchRequest(request: Request): Promise - public createRequest(spec: UrlSpec, init?: RequestInit) { - return new Request(this.createUrl(spec), init) + public createRequest(spec: UrlSpec, init?: RequestInit) { + return new Request(this.createUrl(spec), init) } public createUrl({ @@ -179,11 +180,6 @@ class RemoteEnvironment extends TestEnvironment { } } -// There seem to be conflicting type definitions of `RequestInit` in `node`, -// `cloudflare-worker` and `undici-types`. With the following code the always -// use the `RequestInit` definition coresponding to the `Request` class. -type RequestInit = ConstructorParameters[1] - interface Config { env: { [Environment in RemoteEnvironmentName]: { diff --git a/package.json b/package.json index 1078e82d..19227804 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "@testing-library/jest-dom": "^6.1.4", "@types/iarna__toml": "^2.0.5", "@types/jest": "^29.5.8", - "@types/node": "^18.18.9", "@typescript-eslint/eslint-plugin": "^6.11.0", "@typescript-eslint/parser": "^6.11.0", "cross-env": "^7.0.3", diff --git a/src/frontend-proxy.ts b/src/frontend-proxy.ts index 7a787816..87f0bc8d 100644 --- a/src/frontend-proxy.ts +++ b/src/frontend-proxy.ts @@ -59,7 +59,7 @@ async function fetchBackend({ backendUrl.pathname = backendUrl.pathnameWithoutTrailingSlash } - const response = await fetch(backendUrl.toString(), { + const response = await fetch(new Request(backendUrl.toString(), request), { redirect: route.__typename === 'Frontend' ? route.redirect : 'manual', }) diff --git a/src/index.ts b/src/index.ts index cc236ea5..5c4bcee0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -76,5 +76,5 @@ async function semanticFileNames(request: Request) { url.pathname = `${prefix}${hash}.${extension}` } - return await fetch(url.href, { headers: request.headers }) + return await fetch(url.href, request) } diff --git a/src/utils/url.ts b/src/utils/url.ts index e19c628a..48cbbf52 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -47,7 +47,12 @@ export class Url extends URL { return Response.redirect(this.toString(), status) } - public static fromRequest(request: Request): Url { + // This avoids type errors in the case there are differen incompatible type + // definitions for `Request` (we only need the `url` parameter of the + // `request` object anyways). + // + // See also https://github.com/cloudflare/workerd/issues/1298 + public static fromRequest(request: { url: string }): Url { return new Url(request.url) } } diff --git a/yarn.lock b/yarn.lock index feef1064..7d62c52c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1239,7 +1239,6 @@ __metadata: "@testing-library/jest-dom": ^6.1.4 "@types/iarna__toml": ^2.0.5 "@types/jest": ^29.5.8 - "@types/node": ^18.18.9 "@typescript-eslint/eslint-plugin": ^6.11.0 "@typescript-eslint/parser": ^6.11.0 cross-env: ^7.0.3 @@ -1464,15 +1463,6 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^18.18.9": - version: 18.18.9 - resolution: "@types/node@npm:18.18.9" - dependencies: - undici-types: ~5.26.4 - checksum: 629ce20357586144031cb43d601617eef45e59460dea6b1e123f708e6885664f44d54f65e5b72b2614af5b8613f3652ced832649c0b991accbc6a85139befa51 - languageName: node - linkType: hard - "@types/parse-json@npm:^4.0.0": version: 4.0.0 resolution: "@types/parse-json@npm:4.0.0" @@ -7605,13 +7595,6 @@ __metadata: languageName: node linkType: hard -"undici-types@npm:~5.26.4": - version: 5.26.5 - resolution: "undici-types@npm:5.26.5" - checksum: 3192ef6f3fd5df652f2dc1cd782b49d6ff14dc98e5dced492aa8a8c65425227da5da6aafe22523c67f035a272c599bb89cfe803c1db6311e44bed3042fc25487 - languageName: node - linkType: hard - "undici@npm:^5.22.1": version: 5.26.3 resolution: "undici@npm:5.26.3"