Skip to content
Back

[CLOSED] CORS error using the Locale API from a browser: CORS Allow Origin Not Matching Origin

  • 0
  • Resolved
  • 2
  • Self Hosted
  • Web
Lexy
21 Nov, 2025, 13:39

When I call the GET /v1/locale API with JS in a browser the GET request fails with CORS Allow Origin Not Matching Origin.

Requests to GET /v1/databases/... work fine and return the correct access-control-allow-origin header (domain.com), but the /v1/locale returns the Appwrite url only (api.domain.com). The OPTION request for the locale also succeeds with the correct header.

I have added the domain as a platform in the console.

TL;DR
The CORS error was due to initializing the Locale and Databases with a null client. Solution: Fix the code by initializing the client, databases, and locale properly while ensuring the endpoint URLs are correct. Ultimately resolved by deleting and re-adding the platform and restarting the Appwrite containers. Now, the Locale API call works without issues.
Devika
21 Nov, 2025, 13:44

Are you including your project ID in the request header?

Lexy
21 Nov, 2025, 13:49

Yes, it's sent in the X-Appwrite-Project header. The Databases API and Account API work but not the Locale API

Devika
21 Nov, 2025, 13:53

Can you share the code with me?

Devika
21 Nov, 2025, 13:53

Only the part where you're handling this

Devika
21 Nov, 2025, 13:57

And have you added your domain in the platform?

21 Nov, 2025, 14:19

Here's the code: https://pastebin.com/TgLCanTc

And yes it's added as a Web platform in the console

21 Nov, 2025, 14:23

Response headers: Locale API: https://pastebin.com/rkzUxd9x Databases API: https://pastebin.com/YTewuSB3

21 Nov, 2025, 14:30

The response headers for the OPTIONS request are domain.com for both, it's just the GET request that is different

21 Nov, 2025, 14:54

You have an issue in your code (as per what I know about initializing clients) - In this part:

TypeScript
let client = null;
let databases = new Databases(client);
let locale = new Locale(client);

you are constructing the DB & Locale with client as null.

Then again in this:

TypeScript
export function initClient(config, sessionToken = null) {
  client = new Client()
    .setEndpoint(config.public.appwriteEndpoint)
    .setProject(config.public.appwriteProjectId);
  if (sessionToken != null) {
    client.setSession(sessionToken);
  }
 
  databases = new Databases(client);
  locale = new Locale(client);
}

you are re-defining them. But what's going wrong is that when the part let client... is read, it supposes you've your client undefined. Which causes issues. So please fix your code like this and check whether it works:

TypeScript
import { Client, Databases, Locale } from "appwrite";

let client = null;
let databases = null;
let locale = null;

export function initClient(config, sessionToken = null) {
  client = new Client()
    .setEndpoint(config.public.appwriteEndpoint)
    .setProject(config.public.appwriteProjectId);

  if (sessionToken) client.setSession(sessionToken);

  databases = new Databases(client);
  locale = new Locale(client);
}

export function getLocale() {
  return locale;
}

export function getDatabases() {
  return databases;
}
21 Nov, 2025, 15:03

I changed it to what you wrote but still get the CORS error

21 Nov, 2025, 15:10

Ok. Have checked all your endpoint urls are correct?

21 Nov, 2025, 15:11

And one more thing, can you please also share the Console & Network output?

21 Nov, 2025, 15:30

Yes, the endpoint is only set once when the initClient function is called the first time (and all other Appwrite calls succeed, just not the Locale one) πŸ™‚

https://pastebin.com/E9QKkbyN

21 Nov, 2025, 15:55

I deleted the platform and added it back and restarted the appwrite containers and now it suddenly works without issues

1
21 Nov, 2025, 16:08

So no errors now?

21 Nov, 2025, 16:10

No, the locale call returns {"ip":"172.18.0.1","countryCode":"--","country":"Unknown","continentCode":"--","continent":"Unknown","eu":false,"currency":""}, just need to forward the IP from Nginx πŸ™‚

21 Nov, 2025, 18:53

[CLOSED] CORS error using the Locale API from a browser: CORS Allow Origin Not Matching Origin

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