NPM cors模块在指定时不允许访问

npm cors module not allowed access when specified

本文关键字:定时 不允许 访问 cors 模块 NPM      更新时间:2023-09-26

我正在使用Cors()模块,并相信我在服务器项目上正确使用它:

...
var corsOptions = {
  origin: 'http://localhost:8000'
};
...
app.use(cors());
...
app.post('/auth/instagram',  cors(corsOptions), function(req, res) {
     var accessTokenUrl = 'https://api.instagram.com/oauth/access_token';
      .....

然而,当终端被客户端击中时,我仍然在控制台中收到以下消息:(注:服务器端在3000端口,客户端在8000端口)

XMLHttpRequest cannot load http://localhost:3000/auth/instagram. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8000' is therefore not allowed access. 

必须指定以下内容:

app.use(cors({credentials: true, origin: true}));