fix: .well-known static folder not working (#3676)

This folder is typically used for site metadata like `security.txt` and
other stuff.
This commit is contained in:
Marvin Hagemeister
2026-02-11 14:19:33 +01:00
committed by GitHub
parent 9f68496aa9
commit 3d8091602c
2 changed files with 41 additions and 4 deletions
+36
View File
@@ -281,6 +281,42 @@ Deno.test({
sanitizeResources: false,
});
Deno.test({
name: "Builder - .well-known static files",
fn: async () => {
await using _tmp = await withTmpDir();
const tmp = _tmp.dir;
const foo = path.join(tmp, ".well-known", "foo.json");
await Deno.mkdir(path.dirname(foo), { recursive: true });
await Deno.writeTextFile(foo, JSON.stringify({ ok: true }));
const builder = new Builder({
outDir: path.join(tmp, "dist"),
staticDir: tmp,
});
const app = new App().use(staticFiles());
const abort = new AbortController();
const port = 8011;
await builder.listen(() => Promise.resolve(app), {
port,
signal: abort.signal,
});
const res = await fetch(
`http://localhost:${port}/.well-known/foo.json`,
);
const json = await res.json();
await abort.abort();
expect(res.ok).toBe(true);
expect(res.status).toBe(200);
expect(json).toEqual({ ok: true });
},
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test({
name: "Builder - write prod routePattern",
fn: async () => {
+5 -4
View File
@@ -142,7 +142,7 @@ export class MemoryBuildCache<State> implements DevBuildCache<State> {
for (let i = 0; i < transformed.length; i++) {
const file = transformed[i];
const relative = path.relative(this.#config.staticDir, file.path);
if (relative.startsWith(".")) {
if (relative.startsWith("..")) {
throw new Error(
`Processed file resolved outside of static dir ${file.path}`,
);
@@ -158,7 +158,7 @@ export class MemoryBuildCache<State> implements DevBuildCache<State> {
try {
const filePath = path.join(this.#config.staticDir, pathname);
const relative = path.relative(this.#config.staticDir, filePath);
if (!relative.startsWith(".") && (await Deno.stat(filePath)).isFile) {
if (!relative.startsWith("..") && (await Deno.stat(filePath)).isFile) {
const pathname = new URL(relative, "http://localhost").pathname;
this.addUnprocessedFile(pathname, this.#config.staticDir);
return this.readFile(pathname);
@@ -301,8 +301,9 @@ export class DiskBuildCache<State> implements DevBuildCache<State> {
includeDirs: false,
includeFiles: true,
followSymlinks: false,
// Skip any folder or file starting with a "."
skip: [/\/\.[^/]+(\/|$)/],
// Skip any folder or file starting with a ".", but allow
// ".well-known" for things like PWA manifests
skip: [/\/\.(?!well-known)[^/]+(\/|$)/],
});
for await (const entry of entries) {