简体   繁体   中英

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.

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('/'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM