Back

[SOLVED] How to allow appwrite to accept requests from localhost?

  • 0
  • Self Hosted
  • Web
  • Cloud
kathelia.dokgu
29 Jul, 2023, 03:30

When I added a platform to my project I specifed localhost as the hostname. But when making requests I get this error:

Access to XMLHttpRequest at 'https://cloud.appwrite.io/v1/account' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

TL;DR
The user solved their issue by correctly updating their environment variable from `APPWRITE_PROJECT_ID` to `NEXT_PUBLIC_APPWRITE_PROJECT_ID`. They also mentioned that they have all services enabled on their self-hosted instance of Appwrite, except for GraphQL. They encountered a 404 error when making a request to the `create` function on the frontend. They asked how to allow localhost on their self-hosted instance, to which someone replied that localhost is allowed by default and the error is likely caused by something else, such as an incorrect project ID or lack of access to the API being called. Another user mentioned that they encountered a CORS error
Drake
29 Jul, 2023, 03:44

Localhost is allowed by default. You're probably getting that error for some other reason...like incorrect project id. Or you don't have access to whatever API you're hitting.

Drake
29 Jul, 2023, 03:44

Share the network logs if you still need help

kathelia.dokgu
29 Jul, 2023, 04:05

I double checked and re-copied the correct IDs into my env file. In terms of services, I have everything enabled except for GraphQL. When I looked at the network tab this is really all I saw:

TypeScript
Request URL: https://cloud.appwrite.io/v1/account
Request Method: POST
Status Code: 404
Referrer Policy: strict-origin-when-cross-origin

On my frontend I'm just calling:

TypeScript
const userAccount = await account.create(
  ID.unique(),
  email,
  password,
  `${firstname} ${lastname}`
);

Also, just wondering, on my self-hosted instance of appwrite, what should I do to also allow localhost just like you say localhost is allowed by default on the cloud solution?

kathelia.dokgu
29 Jul, 2023, 04:25

Ah, I figured out the issue - my env was named something like APPWRITE_PROJECT_ID which was fine because I initially was doing my appwrite calls from the backend but since I am moving the calls over to the frontend, I needed to use NEXT_PUBLIC_APPWRITE_PROJECT_ID.

Drake
29 Jul, 2023, 04:30

[SOLVED] How to allow appwrite to accept requests from localhost?

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