Skip to content

fix: make static folders with dot such as .well-known allowed#2929

Merged
marvinhagemeister merged 1 commit into
freshframework:mainfrom
csvn:fix/handle-static-dot-folder
May 13, 2025
Merged

fix: make static folders with dot such as .well-known allowed#2929
marvinhagemeister merged 1 commit into
freshframework:mainfrom
csvn:fix/handle-static-dot-folder

Conversation

@csvn

@csvn csvn commented May 13, 2025

Copy link
Copy Markdown
Contributor

This PR intends to address an error logged when opening a DevTools in a Chromium based browser while using Fresh in dev mode.

See error
Error: Processed file resolved outside of static dir C:\Users\<name>\fresh-site\src\static\.well-known\appspecific\com.chrome.devtools.json
    at MemoryBuildCache.readFile (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/dev/dev_build_cache.ts:81:13)
    at eventLoopTick (ext:core/01_core.js:178:7)
    at async freshStaticFiles (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/static_files.ts:30:18)
    at async FreshReqContext.fn (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/mod.ts:99:18)
    at async https://jsr.io/@fresh/core/2.0.0-alpha.29/src/dev/middlewares/error_overlay/middleware.tsx:15:14
    at async FreshReqContext.fn (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/mod.ts:99:18)
    at async fn (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/mod.ts:99:18)
    at async https://jsr.io/@fresh/core/2.0.0-alpha.29/src/app.ts:232:16
    at async mapped (ext:deno_http/00_serve.ts:407:18)

DevTools tries to load a <root>/static/.well-known/appspecific/com.chrome.devtools.json file, which incorrectly is flagged as "outside" the static directory, and thus generates errors instead of 404.

Maybe hidden folders (starting with .) in /static should be opt-in though? I'm not sure if anyone puts folders with . prefix inside static/ without intending them to be accessible?

  • .. throws errors (outside staticDir)
  • . returns "missing file" (unless config.allowHiddenFolders is true)

Automatic workspace folders

I think a follow-up PR could be for the Dev Builder to also implement support for Automatic workspace folders, by returning JSON content automatically at .well-known/appspecific/com.chrome.devtools.json.

I think a good first step is to allow .<folder-name>, especially since .well-known/ has many valid use-cases, and as such is not unreasonable to want to add static files in.

Comment thread src/build_cache.ts
* Fresh middleware to enable file-system based routing.
* ```ts
* // Enable Fresh static file serving
* app.use(freshStaticFles());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good catch!

@marvinhagemeister marvinhagemeister left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, I didn't know that Chrome Devtools supported the .well-known directory. Thanks for making a PR and appreciate the addition of tests 👍

@marvinhagemeister marvinhagemeister merged commit f15f225 into freshframework:main May 13, 2025
7 checks passed
@csvn

csvn commented May 13, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for making a PR and appreciate the addition of tests 👍

I think the tests could be structured a bit better, but was a bit lazy and combined them all into a single test 😅

Great idea, I didn't know that Chrome Devtools supported the .well-known directory.

I might try to create a PR for MemoryBuildCache (for deno run -A dev.ts) to return a valid com.chrome.devtools.json file. Then it's possible for edits in DevTools to directly apply to source files. I saw Angular CLI adding support for this, and Chromium is likely used by a lot of Developers. But not a high prio right now 😃

@csvn csvn deleted the fix/handle-static-dot-folder branch May 13, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants