Invalid URL error in Appwrite and react +vite application

773 views Asked by At

[1][I am getting invalid url error in an appwrite and react + vite website

I have tried console.log(conf.appwriteUrl) to check if url and ProjectID is passing on correctly(they are) and there are no typo in the url and project id ] here is an image of my code :

image here

Error says "Failed to construct 'URL': Invalid URL" and here is an image of an error:

1 https://i.stack.imgur.com/oaqz8.png

2 https://i.stack.imgur.com/oHwbC.png

4

There are 4 answers

1
Haimantika Mitra On

What URL are you using? It is the best to copy paste the server endpoint from the project settings page.

1
adityaoberai On

The Appwrite SDK accepts a string type as the parameter in the client.setEndpoint function, not the URL type. An example of this is:

client
    .setEndpoint('https://cloud.appwrite.io/v1')
    .setProject('[PROJECT-ID]');

Can you check if your type is set correctly in the conf.js file? This might be causing an error cirumstantially.

Additionally, it would help to recheck if the right endpoint has been copied from the Appwrite Console as well.

0
Pratham Yadav On

found the error , i was wraping url in two strings by mistake it was something like this "'https://cloud.appwrite.io/v1'"

but now a new error has appeared saying : Access to XMLHttpRequest at 'https://cloud.appwrite.io/v1;/account' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

0
Itra On

Don't use quotes in your .env.local file. Working example:

VITE_APPWRITE_PROJECT_ID = 111111111111111111111
VITE_APPWRITE_URL = https://cloud.appwrite.io/v1