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?

+++UPDATE+++

Code and usage example:

//serve assets on the dev server only
if ((process.env.NODE_ENV || 'DEVELOPMENT') == 'DEVELOPMENT') {
    app.use(express.static(path.resolve(__dirname,'..','public')));
}

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

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

+++CLOSED++++

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

Answers


Aminadav February 2016

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

app.use('/',express.static('/'))
app.get('/myparamter',function(req,res,next){
    res.send('This Will never be called')

})

But if you do:

app.get('/myparamter',function(req,res,next){
    res.send('This Will be called if you request /myparmeter')
})

// If not another route matches the URL it will server default static file.
app.use('/',express.static('/'))

Post Status

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

Search




Leave an answer