Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions packages/fresh/src/dev/builder_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/fresh/src/dev/dev_build_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Loading