added quartz external wiki
This commit is contained in:
@@ -4,24 +4,34 @@ const WIKI_SERVICE_URL = process.env.WIKI_SERVICE_URL || 'http://wiki:8080'
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { path: string[] } }
|
||||
{ params }: { params: Promise<{ path?: string[] }> }
|
||||
) {
|
||||
try {
|
||||
const path = params.path || []
|
||||
const resolvedParams = await params
|
||||
const path = resolvedParams.path || []
|
||||
const searchParams = request.nextUrl.searchParams.toString()
|
||||
const queryString = searchParams ? `?${searchParams}` : ''
|
||||
const wikiPath = path.length > 0 ? `/${path.join('/')}` : '/'
|
||||
|
||||
const wikiUrl = `${WIKI_SERVICE_URL}${wikiPath}${queryString}`
|
||||
// Ensure no double slashes
|
||||
const baseUrl = WIKI_SERVICE_URL.endsWith('/') ? WIKI_SERVICE_URL.slice(0, -1) : WIKI_SERVICE_URL
|
||||
const wikiUrl = `${baseUrl}${wikiPath}${queryString}`
|
||||
|
||||
console.log(`[Wiki Proxy] Fetching: ${wikiUrl}`)
|
||||
|
||||
const response = await fetch(wikiUrl, {
|
||||
headers: {
|
||||
'User-Agent': request.headers.get('user-agent') || 'Next.js',
|
||||
},
|
||||
// Add timeout
|
||||
signal: AbortSignal.timeout(10000), // 10 second timeout
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
return new NextResponse('Wiki not found', { status: response.status })
|
||||
console.error(`Wiki service returned ${response.status}: ${response.statusText} for ${wikiUrl}`)
|
||||
return new NextResponse(`Wiki not found: ${response.status} ${response.statusText}`, {
|
||||
status: response.status
|
||||
})
|
||||
}
|
||||
|
||||
const contentType = response.headers.get('content-type') || 'text/html'
|
||||
@@ -44,22 +54,24 @@ export async function GET(
|
||||
status: response.status,
|
||||
headers,
|
||||
})
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('Wiki proxy error:', error)
|
||||
return new NextResponse('Error loading wiki', { status: 500 })
|
||||
return new NextResponse(`Error loading wiki: ${error.message || 'Unknown error'}`, {
|
||||
status: 500
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Handle other HTTP methods
|
||||
export async function POST(request: NextRequest, { params }: { params: { path: string[] } }) {
|
||||
export async function POST(request: NextRequest, { params }: { params: Promise<{ path?: string[] }> }) {
|
||||
return GET(request, { params })
|
||||
}
|
||||
|
||||
export async function PUT(request: NextRequest, { params }: { params: { path: string[] } }) {
|
||||
export async function PUT(request: NextRequest, { params }: { params: Promise<{ path?: string[] }> }) {
|
||||
return GET(request, { params })
|
||||
}
|
||||
|
||||
export async function DELETE(request: NextRequest, { params }: { params: { path: string[] } }) {
|
||||
export async function DELETE(request: NextRequest, { params }: { params: Promise<{ path?: string[] }> }) {
|
||||
return GET(request, { params })
|
||||
}
|
||||
|
||||
|
||||
70
app/api/wiki/route.ts
Executable file
70
app/api/wiki/route.ts
Executable file
@@ -0,0 +1,70 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
const WIKI_SERVICE_URL = process.env.WIKI_SERVICE_URL || 'http://wiki:8080'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const searchParams = request.nextUrl.searchParams.toString()
|
||||
const queryString = searchParams ? `?${searchParams}` : ''
|
||||
// Ensure no double slashes
|
||||
const baseUrl = WIKI_SERVICE_URL.endsWith('/') ? WIKI_SERVICE_URL.slice(0, -1) : WIKI_SERVICE_URL
|
||||
const wikiUrl = `${baseUrl}/${queryString}`
|
||||
|
||||
console.log(`[Wiki Proxy] Fetching: ${wikiUrl}`)
|
||||
|
||||
const response = await fetch(wikiUrl, {
|
||||
headers: {
|
||||
'User-Agent': request.headers.get('user-agent') || 'Next.js',
|
||||
},
|
||||
// Add timeout
|
||||
signal: AbortSignal.timeout(10000), // 10 second timeout
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`Wiki service returned ${response.status}: ${response.statusText}`)
|
||||
return new NextResponse(`Wiki service error: ${response.status} ${response.statusText}`, {
|
||||
status: response.status
|
||||
})
|
||||
}
|
||||
|
||||
const contentType = response.headers.get('content-type') || 'text/html'
|
||||
const content = await response.text()
|
||||
|
||||
// Pass through headers
|
||||
const headers = new Headers()
|
||||
headers.set('Content-Type', contentType)
|
||||
|
||||
// Handle CORS if needed
|
||||
headers.set('Access-Control-Allow-Origin', '*')
|
||||
|
||||
// Preserve cache headers
|
||||
const cacheControl = response.headers.get('cache-control')
|
||||
if (cacheControl) {
|
||||
headers.set('Cache-Control', cacheControl)
|
||||
}
|
||||
|
||||
return new NextResponse(content, {
|
||||
status: response.status,
|
||||
headers,
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('Wiki proxy error:', error)
|
||||
return new NextResponse(`Error loading wiki: ${error.message || 'Unknown error'}`, {
|
||||
status: 500
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Handle other HTTP methods
|
||||
export async function POST(request: NextRequest) {
|
||||
return GET(request)
|
||||
}
|
||||
|
||||
export async function PUT(request: NextRequest) {
|
||||
return GET(request)
|
||||
}
|
||||
|
||||
export async function DELETE(request: NextRequest) {
|
||||
return GET(request)
|
||||
}
|
||||
|
||||
@@ -3,13 +3,19 @@
|
||||
import { motion } from 'framer-motion'
|
||||
import Navigation from '@/components/Navigation'
|
||||
import Footer from '@/components/Footer'
|
||||
import { useState } from 'react'
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export default function Wiki() {
|
||||
const [showFullPage, setShowFullPage] = useState(true)
|
||||
const [iframeError, setIframeError] = useState(false)
|
||||
|
||||
// Wiki URL über den Next.js API Proxy
|
||||
const wikiUrl = '/api/wiki'
|
||||
// Wiki URL - konfigurierbar über Umgebungsvariable, Standard: localhost:3033
|
||||
const wikiUrl = process.env.NEXT_PUBLIC_WIKI_URL || 'http://localhost:3033'
|
||||
|
||||
useEffect(() => {
|
||||
// Reset error when URL changes
|
||||
setIframeError(false)
|
||||
}, [wikiUrl])
|
||||
|
||||
if (showFullPage) {
|
||||
// Vollständige Wiki-Seite als iframe
|
||||
@@ -39,17 +45,59 @@ export default function Wiki() {
|
||||
Zur Übersicht
|
||||
</button>
|
||||
</div>
|
||||
<iframe
|
||||
src={wikiUrl}
|
||||
style={{
|
||||
width: '100%',
|
||||
{iframeError ? (
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
height: '100%',
|
||||
border: 'none',
|
||||
padding: '40px',
|
||||
marginTop: '50px',
|
||||
background: '#fff'
|
||||
}}
|
||||
title="doing-it Wiki"
|
||||
/>
|
||||
textAlign: 'center'
|
||||
}}>
|
||||
<h2 style={{ fontSize: '24px', fontWeight: '600', marginBottom: '20px' }}>
|
||||
Wiki konnte nicht geladen werden
|
||||
</h2>
|
||||
<p style={{ color: 'var(--color-text-secondary)', marginBottom: '30px' }}>
|
||||
Bitte versuchen Sie es später erneut oder kontaktieren Sie den Support.
|
||||
</p>
|
||||
<button
|
||||
onClick={() => {
|
||||
setIframeError(false)
|
||||
window.location.reload()
|
||||
}}
|
||||
className="btn btn-primary"
|
||||
>
|
||||
Seite neu laden
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<iframe
|
||||
src={wikiUrl}
|
||||
style={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
border: 'none',
|
||||
marginTop: '50px',
|
||||
background: '#fff'
|
||||
}}
|
||||
title="doing-it Wiki"
|
||||
onError={() => setIframeError(true)}
|
||||
onLoad={(e) => {
|
||||
// Check if iframe loaded successfully
|
||||
try {
|
||||
const iframe = e.target as HTMLIFrameElement
|
||||
if (iframe.contentDocument?.location.href === 'about:blank') {
|
||||
// Iframe might have error
|
||||
setTimeout(() => setIframeError(true), 3000)
|
||||
}
|
||||
} catch (err) {
|
||||
// Cross-origin - can't check, assume it's working
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</main>
|
||||
</>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user