#cors policy block
53 messages · Page 1 of 1 (latest)
What do you mean by disabling cors?
What's the fill error you're getting?
Disabling my chromes cors By doing that, Google Chrome will not send CORS preflight requests and will not validate CORS headers.
Ok. How're you accessing the function?
Via http request
But by calling the function domain or through appwrite API?
By calling function domain
Ok. Do you have set your frontend and function domain in the appwrite settings?
Yes, I have tried by adding both , I even used wildcard
Could you send the full error or errors?
Okay
Access to fetch at 'http://aa84263eed579ef.mydomain.com/top-users?criteria=alltime' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Do you get any other errors apart from this one?
No
Even when I use Sdk i get the same error
Then that means the problem is inside the function I think
What's it's code?
Iam using database only, my app do not require logging, incase this is the case
I have sawn it, this hasn’t fixed my problem.
Looking at your code, it doesn't seem like you did what was suggested in the thread
Really 😢 what was that
Please help me🙏
Like Binyamin said:
You'll need to add the
CORSyourself
For example allow allreturn res.json(response,200,{'Access-Control-Allow-Origin': '*',})
I have added that. but yet not fixed. When i search the endpoint it normally prints the response but in my code not working. https://codefile.io/f/SjOX0Q3r3T
This is the new code
My appwrite is self hosted
What's "in your code"? Your JavaScript app? What are the network logs there?
Yeah iam using reactjs
This is how Iam excuting using sdk https://codefile.io/f/pll2idbwYS
This is http request to the endpoint https://codefile.io/f/pn7QRI2YbF
It also looks like you're using an API key client side. You should not be doing that because it exposes your API key
So your executions are working fine, right? It's the get execution that's throwing an exception?
What exactly do you mean by "it's not working"?
Okay🙏
Not working
Cors error
Access to fetch at 'http://aa84263eed579ef.mydomain.com/top-users?criteria=alltime' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Should you be using https?
What are the network logs from your browser dev tools?
Iam using http
how shall I send you the log?
Request Method:
OPTIONS
Status Code:
204 No Content
Referrer Policy:
strict-origin-when-cross-origin
Access-Control-Allow-Headers:
Content-Type, Authorization, X-Requested-With
Access-Control-Allow-Methods:
GET, POST, OPTIONS
Access-Control-Allow-Origin:
*
Content-Type:
application/json; charset=utf-8
Date:
Sun, 21 Jul 2024 08:11:27 GMT
Server:
swoole-http-server
X-Debug-Speed:
0.033813953399658
Accept:
/
Accept-Encoding:
gzip, deflate
Accept-Language:
en-US,en;q=0.9
Access-Control-Request-Headers:
content-type,x-asbek-key,x-asbek-project
Access-Control-Request-Method:
GET
Connection:
keep-alive
Referrer Policy:
strict-origin-when-cross-origin
Content-Type:
application/json
Referer:
http://localhost:3000/
User-Agent:
Screenshot showing the responses and the response headers of the options request
I just deleted the function and re created new one and the problem I was having have solved but, when I request https domain Iam getting insecure CMLHttp request endpoint, content must be served over https
Is there way appwrite hive certificate for the function domain? It’s self hosted
on doc it says "Appwrite generates TLS certificates to enforce HTTPS on all Appwrite Functions domains, generated or custom. These domains are safe to use and access in production."
Where does it say that? I think we need to update it.
Appwrite doesn't generate certificates for the auto-generated function domains. See #1261339075118370969 message
can we docker compose exec appwrite ssl domain="auto generated function domain" ?
Sure, but it's inefficient to have to run that for every new function
What if I have multiple functions? Ho do I add it in .env