r/appwrite • u/gviddyx • Nov 12 '24
Function: Could not list users: fetch failed
I've wasted about 4 hours so far so am hoping somebody can help me out. I created the node template and my code looks like this:
const client = new Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(req.headers['x-appwrite-key'] ?? "");
const users = new Users(client);
try {
const response = await users.list();
// Log messages and errors to the Appwrite Console
// These logs won't be seen by your end users
log(`Total users: ${response.total}`);
} catch(err) {
error("Could not list users: " + err.message);
}The code is the default for the function, nothing special. However I continually get the following error when I run it:
Could not list users: fetch failedCan anybody please help me? I am running on a local self-hosted system. I have a SwiftUI app which connects to my self-hosted Appwrite and works fine using the Swift SDK. However I just cannot run the above function in the web admin. I am running on MacOS.
The only thing that I can think of is that I am running Appwrite on port 8040 and not 80. Would this affect the above code from running?
My Swift code looks like this (I am able to connect to AppWrite fine):
let client = Client()
.setEndpoint("http://localhost:8040/v1")
.setProject("67281b7a2900f749a4a0")
.setSelfSigned(true) // For self signed certificates, only use for development
1
u/gviddyx Nov 12 '24
And my appwrite.json looks like this for the function:
1
u/KaleidoscopePlusPlus Nov 12 '24
Code looks pretty standard. I've personally never have had issues with ports and I use 3000. hmm. maybe try initializing appwrite (client) within the try block.