Skip to content

Commit 3f2deb1

Browse files
Add renderUrl support to ProjectPreview for improved authentication handling
Refactor ProjectPreview component to use async data fetching with error handling and remove loading state Fixes preview bug
1 parent acf2722 commit 3f2deb1

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

app/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ export default async function DashboardPage() {
2626
</header>
2727

2828
<main className="container mx-auto px-4 py-8">
29-
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
29+
<div className="grid gap-6 grid-cols-1">
3030
{projectStatuses.map(({status, ...project}) => (
3131
<Link
3232
key={project.slug}
3333
href={`/${project.slug}`}
3434
className="group transition-transform hover:scale-[1.02]"
3535
>
3636
<Card className="h-full overflow-hidden border-2 transition-colors hover:border-primary">
37-
<ProjectPreview url={project.visitLink} title={project.title}/>
37+
<ProjectPreview
38+
url={project.visitLink}
39+
title={project.title}
40+
renderUrl={project.renderUrl}
41+
/>
3842

3943
<CardHeader>
4044
<div className="flex items-start justify-between gap-2">

components/project-preview.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ import {ExternalLink} from "lucide-react"
55
interface ProjectPreviewProps {
66
url: string
77
title: string
8+
renderUrl?: string
89
}
910

10-
export async function ProjectPreview({url, title}: ProjectPreviewProps) {
11+
export async function ProjectPreview({url, title, renderUrl}: ProjectPreviewProps) {
1112
let htmlContent = ""
1213
let error = false
1314

15+
// Use renderUrl if provided, otherwise use the regular url
16+
const urlToFetch = renderUrl || url
17+
1418
try {
15-
const response = await fetch(url, {
19+
const response = await fetch(urlToFetch, {
1620
headers: {
1721
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
1822
},
@@ -46,11 +50,12 @@ export async function ProjectPreview({url, title}: ProjectPreviewProps) {
4650

4751
// Get the base URL (in case of redirects, use the final URL)
4852
const baseUrl = new URL(response.url)
49-
const baseHref = `${baseUrl.protocol}//${baseUrl.host}`
53+
// Use the full origin with trailing slash to ensure all resources load correctly
54+
const baseHref = baseUrl.origin + '/'
5055

5156
// Inject base tag, CSP meta tag (blocking all scripts), and no-scroll style in the head
52-
const baseTag = `<base href="${baseHref}/">`
53-
const cspMeta = `<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'none'; style-src 'self' 'unsafe-inline' https:; img-src * data: blob:; font-src * data:; connect-src * data: blob:;">`
57+
const baseTag = `<base href="${baseHref}">`
58+
const cspMeta = `<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'none'; style-src * 'unsafe-inline'; img-src * data: blob:; font-src * data:; connect-src * data: blob:;">`
5459
const noScrollStyle = `<style>html, body { overflow: hidden !important; }</style>`
5560

5661
if (html.includes('<head>')) {
@@ -70,7 +75,7 @@ export async function ProjectPreview({url, title}: ProjectPreviewProps) {
7075
}
7176

7277
return (
73-
<div className="relative aspect-video w-full overflow-hidden bg-muted rounded-lg border border-border">
78+
<div className="relative w-full h-48 overflow-hidden bg-muted rounded-lg border border-border">
7479
{error ? (
7580
<div className="flex h-full items-center justify-center text-muted-foreground p-4">
7681
<div className="text-center">

lib/projectData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const projects: Project[] = [
66
title: "WESMUN Email",
77
description: "Read-only Web-based email client platform for WESMUN with authenticated access, account-scoped mailboxes, and attachment handling.",
88
visitLink: "https://email.wesmun.com",
9+
renderUrl: "https://email.wesmun.com/login", // Use login page for preview to avoid auth issues
910
routes: [
1011
{
1112
path: "/",

types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface Project {
1212
title: string
1313
description: string
1414
visitLink: string
15+
renderUrl?: string
1516
routes: Route[]
1617
}
1718

0 commit comments

Comments
 (0)