I am developing a flutter web application. When trying to request an api on the wix site it gives the following error
Access to XMLHttpRequest at 'https://www.marketplacesul.com.br/_functions/lojas' from origin' http://web.marketplacesul.com.br 'has been blocked by CORS policy: No' Access-Control-Allow -Origin 'header is present on the requested resource.
Any solution?
This does not work for me, I woul like to access elements of my wix website through iframe of a non-wix website but I can't make it work. Anyone that has another solution? Extra info: the page I want to manipulate is a password-protected page of which I know the password, I would want it to automatically change the input value to the correct password and submit so that only people that access my non-wix website can access the wix website through that iframe.
Change the below origin strings to your own origin.
This should resolve your CORS issue.
import {ok, badRequest, response} from 'wix-http-functions'; function validate(origin) { if (origin == "http://localhost:4200" || origin == "http://localhost:4201") { return true; } else { return false; } } export function options_yourFunctionName(request) { console.log(request); let headers = { "Access-Control-Allow-Methods": "POST, GET, OPTIONS", "Access-Control-Max-Age": "86400" } if (validate(request.headers.origin)) { headers["Access-Control-Allow-Origin"] = request.headers.origin; } return response({ "status": 204, "headers": headers }); } export function post_yourFunctionName(request) { console.log("post_duxLogin"); const _response = { "headers": { "Content-Type": "application/json", } }; if (validate(request.headers.origin)) { _response.headers["Access-Control-Allow-Origin"] = request.headers.origin; _response.headers["Access-Control-Allow-Headers"] = "Content-Type"; } // Perform other things here.... }
You can read more about that in the Wix HTTP Functions API and options.
https://www.wix.com/corvid/reference/wix-http-functions.html#options