【发布时间】:2018-08-20 18:11:08
【问题描述】:
我正在创建一个express 服务器。这是sn-p。
const app = express();
app.use(cookieParser()); // mainly used to retrieve and store CSSO tokens
app.use(bodyParser.json());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "https://the.real.url.com:8081");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Expose-Headers", "Content-Disposition, Content-Type");
res.header("Access-Control-Allow-Credentials", true);
next();
});
目前正在运行。但我需要用regex 替换https://the.real.url.com:8081。
首先,它可以是https 或只是http。
其次,可能有也可能没有端口。等等。
所以当我编辑它时https?://the.real.url.com:8081 允许http 和https。
我收到此错误
The 'Access-Control-Allow-Origin' header contains the invalid value 'https?://the.real.url.com:8081'. Origin 'https://the.real.url.com:8081' is therefore not allowed access.
我还尝试了http(s?)://the.real.url.com:8081、https?://* 和其他变体。它们都不起作用。
所以我想知道Regex 是不允许的吗?但是通配符* 有效。
我做错了吗?
【问题讨论】:
标签: node.js regex express cors