Back

[SOLVED] Flutter Web : CORS Header has a value 'https://localhost'

  • 0
  • General
  • Flutter
  • Accounts
punti_z
28 Aug, 2023, 22:30

Flutter web, deployed on prod server, when trying to create an anonymous session the header for some reason is https://localhost, that gets blocked by cors, even though I have changed the appwrite API endpoint to the prod server in the constants file in my project ??? Not sure what I am missing,

TL;DR
The issue is with CORS (Cross-Origin Resource Sharing) headers in a Flutter Web project. The response header is showing "access-control-allows-origin: https://localhost" instead of the desired app URL. The solution is to add multiple web platforms like "*.example.com", "example.com", and "www.example.com" to the project configuration. This should resolve the issue and allow the app to work properly.
Binyamin
28 Aug, 2023, 22:30

Have you added the prod server url as web/flutter web platform in the project overview page?

punti_z
28 Aug, 2023, 23:40

I did, added a wildcard domain *.myapp.com

Binyamin
28 Aug, 2023, 23:42

One last check

Binyamin
28 Aug, 2023, 23:42

Did you also updated the project id?

Binyamin
28 Aug, 2023, 23:42

You'll get CORS when project is is mismatched

Drake
28 Aug, 2023, 23:54

What exactly are the full browser console logs and what are the request headers for the failed request?

punti_z
29 Aug, 2023, 19:17

Sorry for the late response. The console log is "CORS Allow Origin Not Matching Origin". Looking at the request header the Request Headers Origin is my apps URL but Response headers has " access-control-allows-origin: https://localhost"

punti_z
29 Aug, 2023, 19:28

So the request header origin mismatches the response header allow origin. Now the question is why is the response header origin localhost. Found nothing is .env file. Looked at the platform and that's also also added flutter web *.myapp.com ..

punti_z
29 Aug, 2023, 19:43

I hope in don't need to add both. Just have flutter web added. Also dont have any custom domains configured but did the domain SSL via .env file .. Could no custom domain be causing appwrite server to respond with origin localhost ?

punti_z
29 Aug, 2023, 21:19

Fixed the issue. Just add multiple web platforms like "*.example.com" , "example.com" "www.example.com" .. Should work

punti_z
29 Aug, 2023, 21:20

[Closed] Flutter Web : CORS Header has a value 'https://localhost'

punti_z
29 Aug, 2023, 21:21

[SOLVED] Flutter Web : CORS Header has a value 'https://localhost'

Binyamin
30 Aug, 2023, 00:36

<a:agooglethumbsup:635256484682530825>

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more