From f3546d36347fe5f96990b7d79249478ac2e47394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jani=20Ev=C3=A4kallio?= Date: Sat, 30 Sep 2023 19:35:53 -0500 Subject: [PATCH 1/2] Implement simple nextjs proxy --- nextjs-example/app/page.tsx | 9 +++++++-- nextjs-example/next.config.js | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/nextjs-example/app/page.tsx b/nextjs-example/app/page.tsx index fd75a47..96f11f7 100644 --- a/nextjs-example/app/page.tsx +++ b/nextjs-example/app/page.tsx @@ -1,12 +1,17 @@ import { Reactions } from "./components/Reactions"; +import { headers } from "next/headers"; const ROOM_ID = "next"; export default async function Home() { // fetch initial data in server component for server rendering - const roomHost = "example-reactions.jevakallio.partykit.dev"; + const roomHost = headers().get("host") + "/partykit"; const roomId = ROOM_ID; - const req = await fetch(`https://${roomHost}/party/${roomId}`, { + const protocol = + roomHost.startsWith("localhost") || roomHost.startsWith("127.0.0.1") + ? "ws" + : "wss"; + const req = await fetch(`${protocol}://${roomHost}/party/${roomId}`, { method: "GET", next: { revalidate: 0 }, }); diff --git a/nextjs-example/next.config.js b/nextjs-example/next.config.js index 767719f..fc06a8a 100644 --- a/nextjs-example/next.config.js +++ b/nextjs-example/next.config.js @@ -1,4 +1,16 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {} +const nextConfig = () => { + const rewrites = async () => [ + { + source: "/partykit/:path*", + //destination: "http://localhost:1999/:path*", + destination: "https://example-reactions.jevakallio.partykit.dev/:path*", + }, + ]; -module.exports = nextConfig + return { + rewrites, + }; +}; + +module.exports = nextConfig; From ce02c27015e2ca8d7c67e3dc480d93683c73bd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jani=20Ev=C3=A4kallio?= Date: Sat, 30 Sep 2023 19:38:10 -0500 Subject: [PATCH 2/2] Oopsie --- nextjs-example/app/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nextjs-example/app/page.tsx b/nextjs-example/app/page.tsx index 96f11f7..5d80b58 100644 --- a/nextjs-example/app/page.tsx +++ b/nextjs-example/app/page.tsx @@ -9,8 +9,8 @@ export default async function Home() { const roomId = ROOM_ID; const protocol = roomHost.startsWith("localhost") || roomHost.startsWith("127.0.0.1") - ? "ws" - : "wss"; + ? "http" + : "https"; const req = await fetch(`${protocol}://${roomHost}/party/${roomId}`, { method: "GET", next: { revalidate: 0 },