Dns 具有多个域的凭据和白名单的CORS

Dns 具有多个域的凭据和白名单的CORS,dns,cors,whitelist,Dns,Cors,Whitelist,我正在尝试启用CORS以允许多个域的白名单,上载图像并使用GET使用res.sendFile检索图像 这些都是基于我的CORS设置独立工作的,但我无法让它们一起工作 我正在使用ubuntu、nginx、nodejs 以下内容适用于多域白名单和上载: var whitelist = ['http://localhost:8100', 'https://somedomain.com']; var corsOptions = { origin: function (origin, callback)

我正在尝试启用CORS以允许多个域的白名单,上载图像并使用GET使用res.sendFile检索图像

这些都是基于我的CORS设置独立工作的,但我无法让它们一起工作

我正在使用ubuntu、nginx、nodejs

以下内容适用于多域白名单和上载:

var whitelist = ['http://localhost:8100', 'https://somedomain.com'];
var corsOptions = {
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
  callback(null, true)
} else {
  callback(new Error('Not allowed by CORS'))
}
app.use(cors(corsOptions));
但是,当使用GET使用sendFile检索图像时,这会失败

当我像这样设置CORS时,使用GET检索图像是有效的:

app.use(cors({credentials: true, origin: 'http://localhost:8100'}));

但这不允许多个域

我已尝试将以下内容添加到corsOptions中:

methods: 'GET,PUT,POST',
credentials: true,
那是行不通的


感谢您的建议。

好的,这似乎很有效,但如果有更好的方法,我会向您提供建议

var whitelist = ['http://localhost:8100', 'https://somedomain.com'];
app.use(cors({credentials: true, origin: whitelist }));
谢谢

var whitelist = ['http://localhost:8100', 'https://somedomain.com'];
app.use(cors({credentials: true, origin: whitelist }));