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

Change to just middleware? #32

Closed
greggman opened this issue Nov 3, 2019 · 1 comment
Closed

Change to just middleware? #32

greggman opened this issue Nov 3, 2019 · 1 comment

Comments

@greggman
Copy link

greggman commented Nov 3, 2019

Sorry if this is a dumb question but have you thought about removing the serveStatic part?

As it is I call something like

app.use("/", expressStaticGzip("/my/rootFolder/"));

and it uses both this code and serveStatic but that means it's hard coded to serve static, and a certain version and you have a dependency that needs to be updated etc.

Wouldn't be just as easy yet more flexible to just call next and if I want static files I could do

app.use("/", expressStaticGzip("/my/rootFolder/"));
app.use("/", express.static("/", staticOptions));

And then I could use other things as well?

@greggman greggman closed this as completed Nov 3, 2019
@tkoenig89
Copy link
Owner

Thanks for your feedback.
I acutally did not think about splitting serveStatic from expressStaticGzip before. I could definetly see this as a separate usecase, where you just want to alter the request path and do not want to actually serve a file - so definitely not a dumb question!

But for the scenario where expressStaticGzip is designed for, the serveStatic functionality is required, as i did not want to implement anything that is already implemented by serveStatic. ExpressStaticGzip's purpose is to serve previously compressed files, that lie in some folder. It was initially designed to work standalone, so this is the reason I used serveStatic as a dependency to handle the file serving.
I did some additions to forward options to serveStatic, for people that have other files next to the compressed files or did want to alter caching behaviour of the served files.

I can agree, that there might be cases, where you have a more complex setup and want more control over serveStatic, but i guess, this needs to be handled during the setup of routing, and can not be solved by expressStaticGzip just not serving files.

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

No branches or pull requests

2 participants