Home Ask Login Register

Developers Planet

Your answer is one click away!

dvine multimedia February 2016

How to make express.static middleware ignore get parameter?

I have a mobile app that loads images via http. I'm using a GET parameter for cache busting. In QA and Production the images are served via S3 and this works fine. But in development I'm serving them directly from my node / express backend with express.static(). But here the get parameter makes static not find the file. Is there a way to tell express.static to ignore GET parameter? I digged around code but could find anything obvious. Ideas?


Code and usage example:

//serve assets on the dev server only
if ((process.env.NODE_ENV || 'DEVELOPMENT') == 'DEVELOPMENT') {

This one works: localhost:3000/assets/avatars/example.png

This one doesn't: localhost:3000/assets/avatars/example.png?v=2


The mistake actually, as suggested below, had nothing to do with static routing. Sincere apologies for wasting your time.


Aminadav February 2016

Express is running all the route you define one after another, so if you do:

    res.send('This Will never be called')


But if you do:

    res.send('This Will be called if you request /myparmeter')

// If not another route matches the URL it will server default static file.

Post Status

Asked in February 2016
Viewed 1,234 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life