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
peerreynders2mo ago
I think you wanted to show the error (rather than the code a second time).
Jack w/o Sally
Jack w/o Sally2mo 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
peerreynders2mo 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.
Jack w/o Sally
Jack w/o Sally2mo 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
peerreynders2mo 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.
Jack w/o Sally
Jack w/o Sally2mo 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
peerreynders2mo ago
Sadly I wouldn't be able to tell you anything that isn't already in the documentation.
Jack w/o Sally
Jack w/o Sally2mo 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
peerreynders2mo ago
Glad you were able to resolve it; wish I could have been more help.
Want results from more Discord servers?
Add your server
More Posts
Error: Hydration Mismatch.Why does my project show a hydration error on the first local render, but it loads fine after refresA simple case(ts) of using "native drag(webapi)" with solid.Perhaps useful for some people: https://gist.github.com/beoxgame/4a973c2764c1935b10ccfba8f1a8a138How to export setter function for component?Hi, I'm relatively new to Solid world and whole frontend, I used to work in Java style codebases. I createAsync vs createResource and how does Suspense work?Hello. From doing some searches in here it looks like `createAsync` (+`cache`) seems to be the new rtree structure: granular updates and retain open statecan only replace the whole tree at once so I tried reconcile with a store, but I don't want all <detdeploying a solid js app in render while consuming a backend apiif i'll need to make the code into production & i have the backend url hosted, ```js const BACKENDHow do i fetch data correctly in a route?Hi, I am currently trying to fetch a .json, which I just need to import an array, that I then assignAdding new element to an array before the last element inside solid store```tsx const [tabStore, setTabStore] = createStore<{ contents: TabContent[] }>({ contents: [ {Using SolidStart's prisma template app, getting odd error & crash from the route.Crash log: ``` /home/ile/src/polvirekisteri/polvet/node_modules/@solidjs/start/dist/server/StartSerModularizing Componentshow would you tackle this, right now i have two different components as pages & now requirements i'm