Additional GET requests before POST request that m

2019-09-09 16:12发布

问题:

Only in production, and never on localhost, superagent seems to made additional GET request right before POST requests. This is similar to this unanswered question however that was using other software, this is simply superagent.

The client code is simple a POST request:

superagent
.post('/api/v1/csr/whois')
.send({
    someKey: someValue
})
.end(function(res){
    log('Whois response:', res)
})

回答1:

This is Cross Origin Request Sharing.

The additional GET requests are CORS 'pre-flight' requests. This was fixed in node/express app using:

var cors = require('cors');
app.use(cors());