📜  将多个域 cors 策略列入白名单 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:09.757000             🧑  作者: Mango

代码示例1
const whitelist = ['http://example1.com', 'http://example2.com']
const corsOptions = {
  origin: function (origin, callback) {
    if (whitelist.indexOf(origin) !== -1) {
      callback(null, true)
    } else {
      callback(new Error('Not allowed by CORS'))
    }
  },
}