Skip to content

serveStatic doesn't work with extensionless files #2251

@oscarotero

Description

@oscarotero

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:
imaxe

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

Error: Not a directory (os error 20): open './_site/pagefind/pagefind.unknown_278027f53872923.pf_meta/index.html'

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions