A mobile build trying to connect to the server throws this error:
XMLHttpRequest cannot load https://www.domain.com/_timesync. Origin null is not allowed by Access-Control-Allow-Origin. Error syncing to server time
How do I fix this CORS problem? I tried putting this code in the server but it still throws the same error:
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();
});
I have also tried replacing connectHandlers
to rawConnectHandlers
and it still throws the the same error.