next-prisma-websockets-starter explanation

This is the repo I'm trying to copy websocket setup from... https://github.com/trpc/examples-next-prisma-websockets-starter Inside of the server folder in this template, [https://github.com/trpc/examples-next-prisma-websockets-starter/tree/main/src/server] there is a prodServer.ts file and a wssDevServer.ts file. How are these files used?? When and how is the prodServer.ts file used(ran) and how is the wssDevServer.ts file ran? Because in the trpc.ts file [https://github.com/trpc/examples-next-prisma-websockets-starter/blob/main/src/utils/trpc.ts] the wsLink is used but there are no checks for dev or prod. And WS_URL is imported from publicRuntimeConfig. This is confusing. The tRPC docs also do it differently. They hardcode the websocket urls. And there are no checks for dev and prod.
GitHub
GitHub - trpc/examples-next-prisma-websockets-starter: 🏓 tRPC Next....
🏓 tRPC Next.js WebSocket Starter. Contribute to trpc/examples-next-prisma-websockets-starter development by creating an account on GitHub.
38 Replies
kenny
kennyOP2y ago
This is what my trpc.ts file in the utils folder looks like
import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import superjson from "superjson";

import { type AppRouter } from "@/server/api/root";

const getBaseUrl = () => {
if (typeof window !== "undefined") return "";
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
};

export const api = createTRPCNext<AppRouter>({
config() {
return {
transformer: superjson,
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
}),
],
};
},
ssr: false,
});

export type RouterInputs = inferRouterInputs<AppRouter>;

export type RouterOutputs = inferRouterOutputs<AppRouter>;
import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import superjson from "superjson";

import { type AppRouter } from "@/server/api/root";

const getBaseUrl = () => {
if (typeof window !== "undefined") return "";
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
};

export const api = createTRPCNext<AppRouter>({
config() {
return {
transformer: superjson,
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
}),
],
};
},
ssr: false,
});

export type RouterInputs = inferRouterInputs<AppRouter>;

export type RouterOutputs = inferRouterOutputs<AppRouter>;
I want to add my websocket url to this. But the template from github does it differently. the docs also do it differently. Web dev simplified on Youtube also has a different setup. This is my wssServer.ts file
import { createContext } from "./context";
import { appRouter } from "./api/root";
import { applyWSSHandler } from "@trpc/server/adapters/ws";
import ws from "ws";

const wss = new ws.Server({
port: 3001,
});
const handler = applyWSSHandler({ wss, router: appRouter, createContext });

wss.on("connection", (ws) => {
console.log(`➕➕ Connection (${wss.clients.size})`);
ws.once("close", () => {
console.log(`➖➖ Connection (${wss.clients.size})`);
});
});
console.log("✅ WebSocket Server listening on ws://localhost:3001");

process.on("SIGTERM", () => {
console.log("SIGTERM");
handler.broadcastReconnectNotification();
wss.close();
});
import { createContext } from "./context";
import { appRouter } from "./api/root";
import { applyWSSHandler } from "@trpc/server/adapters/ws";
import ws from "ws";

const wss = new ws.Server({
port: 3001,
});
const handler = applyWSSHandler({ wss, router: appRouter, createContext });

wss.on("connection", (ws) => {
console.log(`➕➕ Connection (${wss.clients.size})`);
ws.once("close", () => {
console.log(`➖➖ Connection (${wss.clients.size})`);
});
});
console.log("✅ WebSocket Server listening on ws://localhost:3001");

process.on("SIGTERM", () => {
console.log("SIGTERM");
handler.broadcastReconnectNotification();
wss.close();
});
tbh I don't know how this is gonna run. It has no exports.
Alejo
Alejo2y ago
Quickly looking at the repo, they seem to simply be called from scripts in package.json, start and dev:wss, For npm run dev, it excecutes pnpm migrate-dev && run-p dev:* which means it is running both dev:next and dev:wss run-p is just a package that lets you run package.json scripts in parallel
kenny
kennyOP2y ago
oww the tRPC don't show the package.json setup I don't think that would work for me tho Cuz it's for pnpm man this is a headache.
techblooded
techblooded2y ago
i did this by hosting a websocket server on railway and a http server on vercel and then connecting the two using redis pub/sub i just put the websocket server in a sep pkg in my monorepo
kenny
kennyOP2y ago
I just got this working for localhost I'm not using a monorepo tho wow,
techblooded
techblooded2y ago
ya but u can just have another ts file and run it concurrently
kenny
kennyOP2y ago
And the same one can be used for locahost and prod right?
techblooded
techblooded2y ago
The ports were different Ya
kenny
kennyOP2y ago
okay I have a separate ws file for prod and localhost this is the production one
import { createContext } from "./context";
import { appRouter } from "@/server/api/root";
import { applyWSSHandler } from "@trpc/server/adapters/ws";
import http from "http";
import next from "next";
import { parse } from "url";
import ws from "ws";

const port = parseInt(process.env.PORT || "3000", 10);
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();

void app.prepare().then(() => {
const server = http.createServer((req, res) => {
const proto = req.headers["x-forwarded-proto"];
if (proto && proto === "http") {
// redirect to ssl
res.writeHead(303, {
location: `https://` + req.headers.host + (req.headers.url ?? ""),
});
res.end();
return;
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const parsedUrl = parse(req.url!, true);
void handle(req, res, parsedUrl);
});
const wss = new ws.Server({ server });
const handler = applyWSSHandler({ wss, router: appRouter, createContext });

process.on("SIGTERM", () => {
console.log("SIGTERM");
handler.broadcastReconnectNotification();
});
server.listen(port);

// tslint:disable-next-line:no-console
console.log(
`> Server listening at http://localhost:${port} as ${
dev ? "development" : process.env.NODE_ENV
}`
);
});
import { createContext } from "./context";
import { appRouter } from "@/server/api/root";
import { applyWSSHandler } from "@trpc/server/adapters/ws";
import http from "http";
import next from "next";
import { parse } from "url";
import ws from "ws";

const port = parseInt(process.env.PORT || "3000", 10);
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();

void app.prepare().then(() => {
const server = http.createServer((req, res) => {
const proto = req.headers["x-forwarded-proto"];
if (proto && proto === "http") {
// redirect to ssl
res.writeHead(303, {
location: `https://` + req.headers.host + (req.headers.url ?? ""),
});
res.end();
return;
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const parsedUrl = parse(req.url!, true);
void handle(req, res, parsedUrl);
});
const wss = new ws.Server({ server });
const handler = applyWSSHandler({ wss, router: appRouter, createContext });

process.on("SIGTERM", () => {
console.log("SIGTERM");
handler.broadcastReconnectNotification();
});
server.listen(port);

// tslint:disable-next-line:no-console
console.log(
`> Server listening at http://localhost:${port} as ${
dev ? "development" : process.env.NODE_ENV
}`
);
});
techblooded
techblooded2y ago
r u trying to connect this to the client?
kenny
kennyOP2y ago
I didn't set notifications to all messages Yes In here
import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import superjson from "superjson";
import { NextPageContext } from "next";
import { wsLink, createWSClient } from "@trpc/client/links/wsLink";

import { type AppRouter } from "@/server/api/root";
import getConfig from "next/config";

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
};

const { publicRuntimeConfig } = getConfig();

const { APP_URL, WS_URL } = publicRuntimeConfig;

function getEndingLink(ctx: NextPageContext | undefined) {
if (typeof window === "undefined") {
return httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
headers() {
if (!ctx?.req?.headers) {
return {};
}
// on ssr, forward client's headers to the server
return {
...ctx.req.headers,
"x-ssr": "1",
};
},
});
}
const client = createWSClient({
url: "ws://localhost:3001/trpc",
});
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(ctx),
],
};
},
ssr: false,
});
export type RouterInputs = inferRouterInputs<AppRouter>;
export type RouterOutputs = inferRouterOutputs<AppRouter>;
import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import superjson from "superjson";
import { NextPageContext } from "next";
import { wsLink, createWSClient } from "@trpc/client/links/wsLink";

import { type AppRouter } from "@/server/api/root";
import getConfig from "next/config";

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
};

const { publicRuntimeConfig } = getConfig();

const { APP_URL, WS_URL } = publicRuntimeConfig;

function getEndingLink(ctx: NextPageContext | undefined) {
if (typeof window === "undefined") {
return httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
headers() {
if (!ctx?.req?.headers) {
return {};
}
// on ssr, forward client's headers to the server
return {
...ctx.req.headers,
"x-ssr": "1",
};
},
});
}
const client = createWSClient({
url: "ws://localhost:3001/trpc",
});
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(ctx),
],
};
},
ssr: false,
});
export type RouterInputs = inferRouterInputs<AppRouter>;
export type RouterOutputs = inferRouterOutputs<AppRouter>;
techblooded
techblooded2y ago
links: [
splitLink({
condition(op) {
return op.type === "subscription";
},
true: wsLink({
client: wsClient,
}),
false: httpBatchLink({
url: `${getBaseUrl(/* websocket = */ false)}/api/trpc`,
}),
}),
],
links: [
splitLink({
condition(op) {
return op.type === "subscription";
},
true: wsLink({
client: wsClient,
}),
false: httpBatchLink({
url: `${getBaseUrl(/* websocket = */ false)}/api/trpc`,
}),
}),
],
the example didn't work for me so i split the link
kenny
kennyOP2y ago
where is your websocket url ah yes I saw WebDevSimplified doing this how not
techblooded
techblooded2y ago
i dont remember i just remember doing split link cuz i was getting errors lemme send code for that
kenny
kennyOP2y ago
alr
techblooded
techblooded2y ago
const wsClient = createWSClient({
url: getBaseUrl(/* websocket = */ true),
});
const wsClient = createWSClient({
url: getBaseUrl(/* websocket = */ true),
});
kenny
kennyOP2y ago
and the getBaseUrl function? I wanna see how you check
techblooded
techblooded2y ago
o it just returns the url to the host:
const getBaseUrl = (websocket = false) => {
/**
* Gets the IP address of your host-machine. If it cannot automatically find it,
* you'll have to manually set it. NOTE: Port 3000 should work for most but confirm
* you don't have anything else running on it, or you'd have to change it.
*/
const localhost = Constants.manifest?.debuggerHost?.split(":")[0];

console.log("Debugger host", localhost);

if (!localhost) {
return websocket
? "wss://PROD_RAILWAY.railway.app"
: "https://PROD_VERCEL.vercel.app";
}
return `${websocket ? "ws" : "http"}://${localhost}:${
websocket ? 3001 : 3000
}`;
};
const getBaseUrl = (websocket = false) => {
/**
* Gets the IP address of your host-machine. If it cannot automatically find it,
* you'll have to manually set it. NOTE: Port 3000 should work for most but confirm
* you don't have anything else running on it, or you'd have to change it.
*/
const localhost = Constants.manifest?.debuggerHost?.split(":")[0];

console.log("Debugger host", localhost);

if (!localhost) {
return websocket
? "wss://PROD_RAILWAY.railway.app"
: "https://PROD_VERCEL.vercel.app";
}
return `${websocket ? "ws" : "http"}://${localhost}:${
websocket ? 3001 : 3000
}`;
};
for my case i did diff ports but u can do same port
kenny
kennyOP2y ago
ahh cool your websocket s always running on railway? didn't know you could check for localhost like that
techblooded
techblooded2y ago
ya i got that from the create-t3-turbo example yep
kenny
kennyOP2y ago
where is your local websocket running? like mine? kewl
techblooded
techblooded2y ago
on local it shud be localhost:3000 for both cuz ur using same port i think
kenny
kennyOP2y ago
Mine's running like this. On port 3001 it currently works when is start dev, my ws also starts:
"scripts": {
"prebuild": "prisma db push",
"build:1-next": "cross-env NODE_ENV=production next build",
"build:2-server": "tsc --project tsconfig.server.json",
"build": "run-s build:*",
"dev:wss": "cross-env PORT=3001 tsx watch src/server/wsDevServer.ts --tsconfig tsconfig.server.json ",
"dev:next": "next dev",
"dev": "run-p dev:*",
"db-up": "docker-compose up -d",
"db-seed": "prisma db seed",
"db-migrate-dev": "prisma migrate dev",
"generate": "prisma generate",
"migrate-dev": "prisma migrate dev",
"migrate": "prisma migrate deploy",
"start": "cross-env NODE_ENV=production node dist/server/wsProdServer.ts",
"studio": "prisma studio",
"lint": "eslint --cache --ext \".js,.ts,.tsx\" --report-unused-disable-directives --report-unused-disable-directives src",
"lint-fix": "npm lint --fix",
"postinstall": "prisma generate"
},
"scripts": {
"prebuild": "prisma db push",
"build:1-next": "cross-env NODE_ENV=production next build",
"build:2-server": "tsc --project tsconfig.server.json",
"build": "run-s build:*",
"dev:wss": "cross-env PORT=3001 tsx watch src/server/wsDevServer.ts --tsconfig tsconfig.server.json ",
"dev:next": "next dev",
"dev": "run-p dev:*",
"db-up": "docker-compose up -d",
"db-seed": "prisma db seed",
"db-migrate-dev": "prisma migrate dev",
"generate": "prisma generate",
"migrate-dev": "prisma migrate dev",
"migrate": "prisma migrate deploy",
"start": "cross-env NODE_ENV=production node dist/server/wsProdServer.ts",
"studio": "prisma studio",
"lint": "eslint --cache --ext \".js,.ts,.tsx\" --report-unused-disable-directives --report-unused-disable-directives src",
"lint-fix": "npm lint --fix",
"postinstall": "prisma generate"
},
techblooded
techblooded2y ago
o shoot i misread mb i thought it was same port
kenny
kennyOP2y ago
np 😉 currently my prod one isnt working it fails when I build and run start
techblooded
techblooded2y ago
wats the log
kenny
kennyOP2y ago
PS C:\Users\kenny\Projects\chat-app> npm run build

> prebuild
> prisma db push

Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "chat-app" at "aws.connect.psdb.cloud"

The database is already in sync with the Prisma schema.

✔ Generated Prisma Client (4.13.0 | library) to .\node_modules\@prisma\client in 217ms


> build
> run-s build:*


> build:1-next
> cross-env NODE_ENV=production next build

info - Loaded env from C:\Users\kenny\Projects\chat-app\.env
info - Linting and checking validity of types .Failed to compile.

./dist/env.mjs:42:24
Type error: Cannot find namespace 'z'.

40 | * middlewares) or client-side so we need to destruct manually.
41 | *
> 42 | * @type {Record<keyof z.infer<typeof server> | keyof z.infer<typeof client>, string | undefined>}
| ^
43 | */
44 | const processEnv = {
45 | DATABASE_URL: process.env.DATABASE_URL,
ERROR: "build:1-next" exited with 1.
PS C:\Users\kenny\Projects\chat-app> npm run build

> prebuild
> prisma db push

Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "chat-app" at "aws.connect.psdb.cloud"

The database is already in sync with the Prisma schema.

✔ Generated Prisma Client (4.13.0 | library) to .\node_modules\@prisma\client in 217ms


> build
> run-s build:*


> build:1-next
> cross-env NODE_ENV=production next build

info - Loaded env from C:\Users\kenny\Projects\chat-app\.env
info - Linting and checking validity of types .Failed to compile.

./dist/env.mjs:42:24
Type error: Cannot find namespace 'z'.

40 | * middlewares) or client-side so we need to destruct manually.
41 | *
> 42 | * @type {Record<keyof z.infer<typeof server> | keyof z.infer<typeof client>, string | undefined>}
| ^
43 | */
44 | const processEnv = {
45 | DATABASE_URL: process.env.DATABASE_URL,
ERROR: "build:1-next" exited with 1.
techblooded
techblooded2y ago
Are you importing z from zod at the top of your env.mjs?
import { z } from "zod";
import { z } from "zod";
kenny
kennyOP2y ago
yes
techblooded
techblooded2y ago
idk then, i think this is some sort of ts issue
kenny
kennyOP2y ago
it prolly has todo with this script
"build:2-server": "tsc --project tsconfig.server.json",
"build:2-server": "tsc --project tsconfig.server.json",
this is my tsconfig.server.json file
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"target": "ES2019",
"lib": ["ES2019", "DOM"],
"isolatedModules": false,
"noEmit": false,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"src/**/*.ts",
"src/**/*.tsx",
".eslintrc.cjs",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.mjs"
]
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"target": "ES2019",
"lib": ["ES2019", "DOM"],
"isolatedModules": false,
"noEmit": false,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"src/**/*.ts",
"src/**/*.tsx",
".eslintrc.cjs",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.mjs"
]
}
And i'm not sure what i'm doing wrong or missing here.
techblooded
techblooded2y ago
My tsconfig compiler options is the following
{
"compilerOptions": {
"target": "es2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true
},
}
{
"compilerOptions": {
"target": "es2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true
},
}
maybe try modifying some of the options
kenny
kennyOP2y ago
there are two tsconfig files when I delete the dist folder and run build again, I don't get the error. If I run the build script again, the error then pops up. Not sure what the cause of that is I get a different error.
Found 58 errors in 19 files.

Errors Files
1 src/components/auth/AuthShowcase.tsx:3
2 src/components/chat/ChatItem.tsx:2
1 src/components/chat/ChatList.tsx:2
3 src/components/chat/ChatMessageForm.tsx:1
1 src/components/chat/ChatsHeader.tsx:4
3 src/components/chat/CreateChatForm.tsx:1
11 src/pages/[chat].tsx:1
1 src/pages/_app.tsx:5
1 src/pages/api/auth/[...nextauth].ts:2
3 src/pages/api/trpc/[trpc].ts:3
3 src/pages/index.tsx:3
2 src/server/api/root.ts:1
9 src/server/api/routers/chat.ts:7
9 src/server/api/routers/message.ts:7
2 src/server/api/routers/user.ts:1
2 src/server/api/trpc.ts:20
2 src/server/auth.ts:12
1 src/server/db.ts:3
1 src/utils/api.ts:14
ERROR: "build:2-server" exited with 2.
Found 58 errors in 19 files.

Errors Files
1 src/components/auth/AuthShowcase.tsx:3
2 src/components/chat/ChatItem.tsx:2
1 src/components/chat/ChatList.tsx:2
3 src/components/chat/ChatMessageForm.tsx:1
1 src/components/chat/ChatsHeader.tsx:4
3 src/components/chat/CreateChatForm.tsx:1
11 src/pages/[chat].tsx:1
1 src/pages/_app.tsx:5
1 src/pages/api/auth/[...nextauth].ts:2
3 src/pages/api/trpc/[trpc].ts:3
3 src/pages/index.tsx:3
2 src/server/api/root.ts:1
9 src/server/api/routers/chat.ts:7
9 src/server/api/routers/message.ts:7
2 src/server/api/routers/user.ts:1
2 src/server/api/trpc.ts:20
2 src/server/auth.ts:12
1 src/server/db.ts:3
1 src/utils/api.ts:14
ERROR: "build:2-server" exited with 2.
these are all import errord like
src/utils/api.ts:14:32 - error TS2307: Cannot find module '@/server/api/root' or its corresponding type declarations.

14 import { type AppRouter } from "@/server/api/root";~
src/utils/api.ts:14:32 - error TS2307: Cannot find module '@/server/api/root' or its corresponding type declarations.

14 import { type AppRouter } from "@/server/api/root";~
@saiansh2525 may I see your package.json? But where is Constants imported from?
techblooded
techblooded2y ago
that was just something specific to expo
OtterSwims996
OtterSwims99611mo ago
@kenny were you able to get your app working with websockets? If possible would you be able to share your repo where you got websockets to work with the t3 create app? I'm trying to do a similar thing where i integrate the prisma repos implementation of websockets into my t3 create app
kenny
kennyOP11mo ago
Hi I still have the repo yes. But I didn't push the changes live iirc cause the web socket functionality wasn't working correctly on a live server. I think the fix was just not to use a local ws url 😅 idk maybe you can figure that out. Here's the repo https://github.com/Beefy-py/chat-app.git. You'd want to check the added websocket functionality commit pls ignore the README.md 🙊
OtterSwims996
OtterSwims99611mo ago
okay thanks i'll give it a shot
OtterSwims996
OtterSwims99611mo ago
I found this guide for how to get websockets to work but its pretty hard for me to navigate and understand the project structre of t3 as a beginner: https://medium.com/@lada496/trpc-102-subscription-web-socket-d81b8962a010
Medium
tRPC 102: Subscription/Web Socket
This is my memo when I implemented a subscription with tRPC along with the official documents. I also referred to the code example provided…
Want results from more Discord servers?
Add your server