websocket (ws package) client connection keeps restarting on ct3a project.

The ws server and next server starts fine, but when I connect with a client it keeps restarting .... this is the utils/app.ts file. Need help figuring out how to fix it. the rest of the code is here: https://github.com/imoxto/inent_v0/tree/ws-server
const getBaseUrl = () => {
if (typeof window !== "undefined") return ""; // browser should use relative url
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; // SSR should use vercel url
return `http://localhost:${process.env.PORT ?? 3000}`; // dev SSR should use localhost
};

function getEndingLink() {
if (typeof window === "undefined") {
return httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
});
}
const client = createWSClient({
url: "ws://localhost:3001",
});

return wsLink<AppRouter>({
client,
});
}

/** A set of type-safe react-query hooks for your tRPC API. */
export const api = createTRPCNext<AppRouter>({
config({ ctx }) {
return {
transformer: superjson,
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
getEndingLink(),
],

queryClientConfig: {
defaultOptions: {
queries: {
staleTime: 180000,
cacheTime: 180000,
retry: false,
},
mutations: {
retry: false,
},
},
},
};
},
ssr: false,
});
const getBaseUrl = () => {
if (typeof window !== "undefined") return ""; // browser should use relative url
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; // SSR should use vercel url
return `http://localhost:${process.env.PORT ?? 3000}`; // dev SSR should use localhost
};

function getEndingLink() {
if (typeof window === "undefined") {
return httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
});
}
const client = createWSClient({
url: "ws://localhost:3001",
});

return wsLink<AppRouter>({
client,
});
}

/** A set of type-safe react-query hooks for your tRPC API. */
export const api = createTRPCNext<AppRouter>({
config({ ctx }) {
return {
transformer: superjson,
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
getEndingLink(),
],

queryClientConfig: {
defaultOptions: {
queries: {
staleTime: 180000,
cacheTime: 180000,
retry: false,
},
mutations: {
retry: false,
},
},
},
};
},
ssr: false,
});
GitHub
GitHub - imoxto/inent_v0 at ws-server
Contribute to imoxto/inent_v0 development by creating an account on GitHub.
0 Replies
No replies yetBe the first to reply to this messageJoin