diff --git a/Dockerfile b/Dockerfile index 47b2562..370f2a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ FROM base as builder # Include all NEXT_PUBLIC_* env vars here ARG NEXT_PUBLIC_POSTHOG_KEY ARG NEXT_PUBLIC_IS_PUBLIC_PLAYGROUND +ARG NEXT_PUBLIC_SOCKET_URL WORKDIR /app COPY --from=deps /app/node_modules ./node_modules diff --git a/render.yaml b/render.yaml index 34643bb..f611537 100644 --- a/render.yaml +++ b/render.yaml @@ -19,3 +19,18 @@ services: name: prompt-lab-prod property: connectionString - fromGroup: prompt-lab-prod + - key: NEXT_PUBLIC_SOCKET_URL + value: https://prompt-lab-prod-wss.onrender.com + # Render support says we need to manually set this because otherwise + # sometimes it checks a different random port that NextJS opens for + # liveness and the liveness check fails. + - key: PORT + value: 10000 + + - type: web + name: prompt-lab-prod-wss + env: docker + dockerfilePath: Dockerfile + dockerContext: . + plan: free + dockerCommand: pnpm tsx src/wss-server.ts diff --git a/src/wss-server.ts b/src/wss-server.ts index e747e40..7b9048f 100644 --- a/src/wss-server.ts +++ b/src/wss-server.ts @@ -2,11 +2,9 @@ import "dotenv/config"; import express from "express"; import { createServer } from "http"; import { Server } from "socket.io"; -import { env } from "./env.mjs"; import cors from "cors"; -// Get the port from SOCKET_URL -const port = env.NEXT_PUBLIC_SOCKET_URL?.split(":")[2] || 3318; +const port = process.env.NEXT_PUBLIC_SOCKET_URL?.split(":")?.[2] ?? process.env.PORT ?? 3318; const app = express(); app.use(cors()); @@ -26,7 +24,7 @@ io.on("connection", (socket) => { }); // When a 'message' event is received, emit it to the room specified - socket.on("message", (msg: { channel: string; payload: any }) => { + socket.on("message", (msg: { channel: string; payload: unknown }) => { socket.to(msg.channel).emit("message", msg.payload); }); });