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

Allow serving pre-compressed files with serveStatic #3363

Closed
inetol opened this issue Sep 2, 2024 · 3 comments · Fixed by #3366
Closed

Allow serving pre-compressed files with serveStatic #3363

inetol opened this issue Sep 2, 2024 · 3 comments · Fixed by #3366
Labels
enhancement New feature or request.

Comments

@inetol
Copy link
Contributor

inetol commented Sep 2, 2024

What is the feature you are proposing?

Adding an option to prioritize pre-compressed files with .br, .zst or .gz extensions and in case they do not exist serve the file as usual. When compressing the assets of a web page in CI, this would help to reduce the server load by avoiding the need to use compress middleware.

@inetol inetol added the enhancement New feature or request. label Sep 2, 2024
@MathurAditya724
Copy link
Contributor

You can use rewriteRequestPath option in serveStatic middleware for this task. Check it out here - https://hono.dev/docs/getting-started/nodejs#serve-static-files

@inetol
Copy link
Contributor Author

inetol commented Sep 3, 2024

I tried to use it before but it does not expose the request/response context, so I cannot set the necessary headers nor do the logic to check if the client is accepting compressed files.

@MathurAditya724
Copy link
Contributor

So, will it be better if the API passes context as the next param? like this -

serveStatic({
  root: './',
  rewriteRequestPath: (path, c) =>
    path.replace(/^\/static/, '/statics'),
})

And also with the new API coming (https://x.com/yusukebe/status/1829780618626146513) it will get much easier

@inetol inetol closed this as completed Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants