0

I have a problem after I have built and published my Flutter Web App. My app is working perfectly when running it from the IDE , Android Studio, with Google chrom in Localhost:somePort.

What I have done:

  • Published my app to my web server and it is working on the web-site with my domain, i.e. www.example.com

  • Created a custom domain in Appwrite console settings for my Appwrite app as ar.example.com,

  • Created A record in the DNS settings of domain, the console of Appwrite is accessible through the browsert at https://ar.example.com/,

  • Created an SSL certification on the Appwrite server according to the docs.

  • Changed the Endpoint of Appwrite in my Flutter app to point to the new address: https://ar.example.com/v1

  • I have modified the .env file in appwrite folder of the Appwrite server to the example.com and www.example.com.

and still after all that , I can open the app in the browser, but is stops running when it tries to run the first command from the server, browser's console gives me a CORS error as follows:

Access to XMLHttpRequest at 'https://ar.example.com/v1/account?#' from origin 'https://example.com/' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'https://localhost/' that is not equal to the supplied origin.
Yahalom Software
  • 616
  • 4
  • 15

2 Answers2

1

This error can occur if:

  1. client.setProject() is not called
  2. the value passed to client.setProject() is incorrect
  3. there is no web platform added in your project that matches the hostname of your app

Also, I'm not sure you should be doing this step:

I have modified the .env file in appwrite folder of the Appwrite server to the example.com and www.example.com.

The APP_DOMAIN* env vars for Appwrite should be set to your main Appwrite hostname.

Steven Nguyen
  • 452
  • 4
  • 4
0

I have found the problem with the help of Appwrite support, hope this helps someone out there.

When creating a project in Appwrite you need to create a platform, in the project's console settings.

It appears that creating the platform as Flutter Web is causing this problem, since the hostname as defined in flutter is expecting a reverse host name, like com.domainName.hostName, and therefore recognized by the browser as a different domain than the client.

The solution is to create a Web platform instead of Flutter web platform.

Appwrite support team has promised they will carefuly look into it and fix what needed.

Yahalom Software
  • 616
  • 4
  • 15
  • I thought you said you had the same hostname value set for flutter web and web platform. Or did you have the reverse when setting up flutter web? – Steven Nguyen Jul 28 '23 at 20:12
  • @StevenNguyen, I obviously added the regular host name when created the Flutter web platform , this is how the console suggests it...... Frankly , I have not tried it as a reverse format of the hostname, doesn't seem right anyway.... – Yahalom Software Jul 30 '23 at 08:35