简体   繁体   中英

Safari blocks CORS request to Express API

I have a simple node/express server which I use as an API for my AngularJS app. It's running at localhost:8080

let express = require('express');
...

let cors    = require('cors');
...

let app     = express();
app.use(cors());

let port    = Number(process.env.PORT || 8080);
...

app.use('/api', require('./routes'));
app.use('*', (req, res) => res.sendStatus(httpStatus[404]).end());

app.listen(port, () => logger.info("✔ Listening on port " + port));

Pretty basic stuff. cors() should be allowing requests from any origin with the methods GET,HEAD,PUT,PATCH,POST,DELETE .

My Angular app at localhost:3000 simply makes a GET request to my server, which runs fine on Firefox and Chrome, but gives me the following on Safari only:

XMLHttpRequest cannot load http://localhost:8080/api/drawings/all. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.

I thought that CORS was handled entirely by the server, and that there shouldn't be cross-browser problems. I've read that Safari is stricter in this regard, but I want to make sure that my users don't have to change something in their preferences in order to get the site to work. Even in the developer console on Safari, checking "Disable Cross-Origin Restrictions" does nothing to help me.

My server logs the request, and returns a 200 status.

清除Safari的缓存可以解决此问题。

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