Skip to content
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

preCompress:true with wildcard:true doesn't use index file if the path doesn't end in / #270

Closed
2 tasks done
cameronbraid opened this issue Mar 17, 2022 · 1 comment · Fixed by #271
Closed
2 tasks done

Comments

@cameronbraid
Copy link
Contributor

cameronbraid commented Mar 17, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

3.27.4

Plugin version

4.5.0

Node.js version

16.13.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

21.04

Description

I expect the index.html.bz file to be served when I request a directory without a trailing slash

I think the solution is to add code in

reply.callNotFound()
that uses findIndexFile and re-tries the pumpSendToReply with a new path name

something like

let indexPathname = findIndexFile(pathname, options.root, options.index)
if (!indexPathname) {
       return reply.callNotFound()
}
return pumpSendToReply(
            request,
            reply,
            indexPathname + '.' + getEncodingExtension(encoding),
            rootPath,
            undefined,
            undefined,
            checkedEncodings
          )

Steps to Reproduce

folder structure

public/SiteMap/index.html.bz
public/SiteMap/index.html

Setup plugin with :

  fastify.register(fastifyStatic, {
    root: resolve("public"),
    redirect: false,
    wildcard: true,
    preCompressed: true,
  })

Request

curl http://localhost:8080/SiteMap

(note no trailing slash)

Get a 404 error

Expected Behavior

I expect the public/SiteMap/index.html.bz file to be served for /SiteMap url

@cameronbraid
Copy link
Contributor Author

I have implemented a fix, can someone please review

mcollina pushed a commit that referenced this issue Mar 17, 2022
* fix: precompressed index without trailing slash (#270)

* feat: move no trailing slash index ndex handler before dir list handler
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 a pull request may close this issue.

1 participant