Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default async function Home({
}: {
searchParams: Promise<any>;
}) {
await headers();
const headersList = await headers();
let { url, content_type_uid } = await searchParams;
const { live_preview } = await searchParams;

Expand All @@ -21,13 +21,16 @@ export default async function Home({
}

const getContent = async () => {
const host = headersList.get('host') || 'localhost:3000';
const protocol = headersList.get('x-forwarded-proto') || 'http';
const baseUrl = `${protocol}://${host}`;

const result = await fetch(
// This could be any external URL
live_preview
? `http://localhost:3000/api/middleware?content_type_uid=${content_type_uid}&url=${encodeURIComponent(
? `${baseUrl}/api/middleware?content_type_uid=${content_type_uid}&url=${encodeURIComponent(
url
)}&live_preview=${live_preview}`
: `http://localhost:3000/api/middleware?content_type_uid=${content_type_uid}&url=${encodeURIComponent(
: `${baseUrl}/api/middleware?content_type_uid=${content_type_uid}&url=${encodeURIComponent(
url
)}`
);
Expand Down
Loading