From b738023a436e656d8d31e91e02527c7eb70358d3 Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Tue, 16 Apr 2024 11:37:26 +0200 Subject: [PATCH] feat: force port 3000 to make Next.js abort startup on multiple instances clashing on same port --- .env.local.example | 1 + env/client.ts | 8 ++++++-- lib/trpc/Provider.tsx | 2 ++ package.json | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.env.local.example b/.env.local.example index 558a6cf35..ad963dfb4 100644 --- a/.env.local.example +++ b/.env.local.example @@ -25,3 +25,4 @@ SEAMLESS_LOGIN_FI="http://www.example.fi/updatelogin" SEAMLESS_LOGIN_NO="http://www.example.no/updatelogin" SEAMLESS_LOGIN_SV="http://www.example.se/updatelogin" WEBVIEW_ENCRYPTION_KEY="MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=" + diff --git a/env/client.ts b/env/client.ts index 678173613..10d0815b0 100644 --- a/env/client.ts +++ b/env/client.ts @@ -2,7 +2,11 @@ import { createEnv } from "@t3-oss/env-nextjs" import { z } from "zod" export const env = createEnv({ - client: { NEXT_PUBLIC_PORT: z.string().optional() }, + client: { + NEXT_PUBLIC_PORT: z.string().default("3000"), + }, emptyStringAsUndefined: true, - runtimeEnv: { NEXT_PUBLIC_PORT: process.env.PORT }, + runtimeEnv: { + NEXT_PUBLIC_PORT: process.env.NEXT_PUBLIC_PORT, + }, }) diff --git a/lib/trpc/Provider.tsx b/lib/trpc/Provider.tsx index b2ccab8e6..f04d2d083 100644 --- a/lib/trpc/Provider.tsx +++ b/lib/trpc/Provider.tsx @@ -10,6 +10,8 @@ import { transformer } from "@/server/transformer" import { trpc } from "./client" function initializeTrpcClient() { + // Locally we set nextjs to run on port to 3000 so that we always guarantee + // that trpc and next are running on the same port. return trpc.createClient({ links: [ httpBatchLink({ diff --git a/package.json b/package.json index 703d51f46..1b57ae279 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "prebuild": "npm run lint", "build": "next build", "predev": "rm -rf .next", - "dev": "next dev", + "dev": "PORT=3000 NEXT_PUBLIC_PORT=3000 next dev", "prelint": "rm -rf .next", "lint": "next lint --max-warnings 0 && tsc", "prelint:fix": "rm -rf .next",