Hey there!
I’m having issues with CORS handling my post requests from a third-party website/app.
(A Unity WebGL embed game).
From what I understand after reading some documentation my header should allow any request from anywhere but somehow it doesn’t go past pre-flight.
import {created, serverError} from 'wix-http-functions';
import wixData from 'wix-data';
export function post_addUserLeaderboard(request) {
let options = {
"headers": {
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Headers": "Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Timekl",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Max-Age": "8000",
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json"
}
};
return request.body.json()
.then( (body) => {
let leaderboardEntry = {
"title": body.Title,
"score": body.Score
}
return wixData.insert("FastLifeLeaderboard", leaderboardEntry)
.then( (result) => {
options.body = {
"inserted": result
};
return created(options);
})
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
});
})
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
});
}
Here’s the error I’m getting in Chrome’s console:
I’ve been on this for 2 days. Some people on stack overflow told me I should configure my server to respond to my POST request with a 200 OK but I can’t seem to figure out how to do that.
Any help with this would be extremely appreciated
Raphael