尝试连接到服务器的移动版本会引发此错误:
XMLHttpRequest cannot load https://www.domain.com/_timesync. Origin null is not allowed by Access-Control-Allow-Origin. Error syncing to server time
如何修复此CORS问题?我尝试将此代码放在服务器中,但它仍然会抛出相同的错误:
WebApp.connectHandlers.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', [
'Accept',
'Accept-Charset',
'Accept-Encoding',
'Accept-Language',
'Accept-Datetime',
'Authorization',
'Cache-Control',
'Connection',
'Cookie',
'Content-Length',
'Content-MD5',
'Content-Type',
'Date',
'User-Agent',
'X-Requested-With',
'Origin'
].join(', '));
return next();
});
我也尝试将connectHandlers
替换为rawConnectHandlers
,但仍然会抛出相同的错误。