S
SolidJS6mo ago
Axolotl

FIXED: fetch error on route load function

const getUser = cache(async (username: string) => {
const data = await fetch(ApiEndpoints.user.auth.WHO_AM_I, {
credentials: "include",
});
console.log(data);
return data;
}, "user");

export const route = {
load: (args) => {
const username = get_username(args.params.user);
console.debug(username);
getUser(username);
},
matchFilters: {
user: (v: string) => v.length > 1 && v.includes("@")
}
} satisfies RouteDefinition;
const getUser = cache(async (username: string) => {
const data = await fetch(ApiEndpoints.user.auth.WHO_AM_I, {
credentials: "include",
});
console.log(data);
return data;
}, "user");

export const route = {
load: (args) => {
const username = get_username(args.params.user);
console.debug(username);
getUser(username);
},
matchFilters: {
user: (v: string) => v.length > 1 && v.includes("@")
}
} satisfies RouteDefinition;
calling getUser function inside load function is causing fetch error. but this same endpoint(ApiEndpoints.user.auth.WHO_AM_I) works outside this load function, so I dont think its server error. also it prefetch data on link hover, so server works, I dont get whats the issue inside function.
9 Replies
peerreynders
peerreynders6mo ago
I think you wanted to show the error (rather than the code a second time).
Axolotl
AxolotlOP6mo ago
oh sorry I forgot that xD here:
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

TypeError: fetch failed
at node:internal/deps/undici/undici:12618:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async eval (/app/src/routes/(user)/[user].tsx?pick=route:10:16) {
cause: Error: connect ECONNREFUSED 0.0.0.0:8000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:128:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '0.0.0.0',
port: 8000
}
}

Node.js v18.20.2
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

TypeError: fetch failed
at node:internal/deps/undici/undici:12618:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async eval (/app/src/routes/(user)/[user].tsx?pick=route:10:16) {
cause: Error: connect ECONNREFUSED 0.0.0.0:8000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:128:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '0.0.0.0',
port: 8000
}
}

Node.js v18.20.2
peerreynders
peerreynders6mo ago
also it prefetch data on link hover, so server works, I dont get whats the issue inside function.
If I read it correctly the client doesn't have any problem performing the fetch, its just that the Solid Start server can't seem to get through to that same server on SSR. So the question is: can the Solid start server make the connection outside of SSR or it there something in its environment preventing it from doing just that.
Axolotl
AxolotlOP6mo ago
yes, solid server cant connect to server. Im running both on a docker (podman) container, I tried running both ends individually on both localhost and 0.0.0.0, that worked. solid server cant connect to server running on container i guess. also I've no clue what to do to accept connection from solid server. do you have any idea on this? sorry this seems like not the problem with solid at all. @peerreynders sorry for the ping, but could you say what you mean by:
can the Solid start server make the connection outside of SSR
thats different from normal fetch?
peerreynders
peerreynders6mo ago
If it was a problem related to SSR then other code like a server function used from the client could still make the fetch work. But if it's related to the container configuration no fetch will work even when it's just for something like node index.js.
Axolotl
AxolotlOP6mo ago
yea, thing bothering me is when I run backend server not on container, it works. also is there anything here that needs to config for solid-start server? (app.config.ts)
No description
peerreynders
peerreynders6mo ago
Sadly I wouldn't be able to tell you anything that isn't already in the documentation.
Axolotl
AxolotlOP6mo ago
@peerreynders hi, fixed this issue. That was actually container routing related, since solid is calling route load api on server (not browser) I needed to add frontend container host to server. Anyways, thank you for your help :D
peerreynders
peerreynders6mo ago
Glad you were able to resolve it; wish I could have been more help.
Want results from more Discord servers?
Add your server