diff --git a/nextjs-example/app/page.tsx b/nextjs-example/app/page.tsx index fd75a47..5d80b58 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") + ? "http" + : "https"; + 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;