Enable HTML handling for HTML files in the public directory#9548
Enable HTML handling for HTML files in the public directory#9548jamesopstad merged 6 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: a9917bf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
fc308dd to
fcb8930
Compare
petebacondarwin
left a comment
There was a problem hiding this comment.
A bit of commentary in the code about the PUBLIC_DIR_PREFIX - what it is for and how it is used - would be helpful to future readers. Otherwise LGTM
| test("worker configs warnings are not present in the terminal", async () => { | ||
| expect(serverLogs.warns).toEqual([]); | ||
| expect(serverLogs.warns.join()).not.toContain( | ||
| "contains the following configuration options which are ignored since they are not applicable when using Vite" |
There was a problem hiding this comment.
Slightly fragile test in the sense that any change to the text will cause this test to pass due to a false positive.
There was a problem hiding this comment.
Yeah, agree it's not ideal. Had to change this as one of the tests does trigger a warning. There's a corresponding test in another variant that tests the opposite.
| const response = await this.env.__VITE_HTML_EXISTS__.fetch(url); | ||
|
|
||
| return exists ? pathname : null; | ||
| return response.json() as Promise<string | null>; |
There was a problem hiding this comment.
NIT:
| return response.json() as Promise<string | null>; | |
| return response.json<string|null>(); |
| } | ||
|
|
||
| export function withTrailingSlash(path: string): string { | ||
| return path[path.length - 1] !== "/" ? `${path}/` : path; |
There was a problem hiding this comment.
NIT:
| return path[path.length - 1] !== "/" ? `${path}/` : path; | |
| return path.endsWith("/") ? path : `${path}/`; |
fcb8930 to
b6711b4
Compare
IgorMinar
left a comment
There was a problem hiding this comment.
This is awesome! Thank you James for getting this working.
…c directory is included in the path
b6711b4 to
a9917bf
Compare
* 'main' of ssh://github.com/cloudflare/workers-sdk: (213 commits) fix(vite-plugin-cloudflare): allow unknown entrypoint on startup (cloudflare#9583) add warning about env not specified to potentially risky wrangler commands (cloudflare#9344) test: correctly delete test d1 databases (cloudflare#9598) Add details to v3 maintenance worflow error message (cloudflare#9602) drop unused `WRANGLER_UNENV_RESOLVE_PATHS` env var (cloudflare#9593) warn instead of erroring if no exposed ports. and remove unused dev_exposed_ports (cloudflare#9573) fix(wrangler): point to the right doc location (replaces cloudflare#9353) (cloudflare#9592) [vitest-pool-worker] Add `type: module` in package.json (cloudflare#9595) Enable HTML handling for HTML files in the public directory (cloudflare#9548) switch from go container to js (cloudflare#9588) containers: switch to Cloudflare container registry (cloudflare#9564) performance improvement: restart a mixed mode session only if the worker's remote bindings have changed (cloudflare#9536) ci: delete more orphaned resources from e2e tests (cloudflare#9580) test: remove `verifyBuildScript` logic from c3 e2e tests (cloudflare#9504) fix(vite-plugin): ensure node compat globals are injected before any imports (cloudflare#9581) feat(containers-shared): Move `isDockerfile` utility function to `containers-shared` (cloudflare#9577) allow `startWorker` to accept `false` as an `inspector` option (to disable the inspector server) (cloudflare#9550) Update capnp generated code from the workerd.capnp (cloudflare#9582) Bump `@cloudflare/unenv-preset` to 2.3.3 (cloudflare#9566) test: make custom build bundling tests more robust (cloudflare#9494) ...
Fixes #9362.
Enable HTML handling for HTML files in the public directory.
HTML files in the public directory are prioritized over those at the root. This is consistent with Vite's internal behaviour, which places the
servePublicMiddlewarefirst.