-
-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serveStatic doesn't work with extensionless files #2251
serveStatic doesn't work with extensionless files #2251
Comments
Is it expected that serveStatic should still log errors when serving extensionless files? To be pedantic, these files do have extensions:
|
I can't fully understand that and cannot reproduce it. So, please create another issue and describe it. If possible, create a minimal project to reproduce it. Thanks. |
I think the actual issue is the filename extension. The original comment in this issue concerns a file named I was confused about why this issue is named "extensionless files" since PageFind creates files with extensions, albeit non-standard extensions, like Whenever the PageFind files are requested via I believe the issue is the underscore in the filename extension. I tried experimenting with different name variations, and this is the result:
So I think the problem is the underscore (or any non-alphanumeric character) in the filename extension causes hono to try to append I believe this is the line where that is happening: Line 19 in 0d851b6
If you wanted to support files with an underscore or dash in the filename extension, then the line should be } else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) { † I see this error |
This is still a problem for me. I'm trying to use an actually extensionless file, My workaround is to save my file with a app.use(
"*",
serveStatic({
root: "./public",
rewriteRequestPath: (path) =>
path.replace(
/^\/\.well-known\/apple-developer-merchantid-domain-association/,
"/.well-known/apple-developer-merchantid-domain-association.txt"
),
})
); |
Hi @ersinakinci Are you running it on Deno? |
Hi @yusukebe, nope running on Node. |
@ersinakinci thanks. This may be fixed with the latest version |
@yusukebe, just upgraded and unfortunately I'm still getting the same error. |
Sorry! I've fixed it and released the new version |
I just wanted to point out how deeply impressive it is that this project responds to its users so quickly. I've used many other projects that take weeks or months to respond. The fact that @yusukebe can release fixes almost immediately is making me love this project. 👏 |
What version of Hono are you using?
4.0.5
What runtime/platform is your app running on?
Deno
What steps can reproduce the bug?
I'm using Pagefind which generates the following file structure:
What is the expected behavior?
When the browser request the file
/pagefind/pagefind.unknown_278027f53872923.pf_meta
it should be served correctly.What do you see instead?
The browser gets a 404 error, and Hono logs
Additional information
This is because Hono automatically add
/index.html
to any file without an extension (See the code here: https://github.com/honojs/hono/blob/main/src/utils/filepath.ts#L19-L21)It should check first if the file exist before adding the
defaultDocument
sufix.The text was updated successfully, but these errors were encountered: