- React dashboard with Tailwind CSS v4 - Session-based authentication (Lucia patterns) - API client with axios - Project, Task, and Agent views - Bun.serve() with HMR and API proxy - Docker support Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import index from './public/index.html'
|
|
|
|
const PORT = process.env.PORT || 3001
|
|
const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000'
|
|
|
|
Bun.serve({
|
|
port: PORT,
|
|
async fetch(req) {
|
|
const url = new URL(req.url)
|
|
|
|
// API proxy to backend
|
|
if (url.pathname.startsWith('/api/')) {
|
|
const backendUrl = `${BACKEND_URL}${url.pathname}${url.search}`
|
|
const headers = new Headers(req.headers)
|
|
|
|
// Forward cookies
|
|
const cookie = req.headers.get('cookie')
|
|
if (cookie) {
|
|
headers.set('cookie', cookie)
|
|
}
|
|
|
|
const backendReq = new Request(backendUrl, {
|
|
method: req.method,
|
|
headers,
|
|
body: req.method !== 'GET' && req.method !== 'HEAD' ? await req.text() : undefined,
|
|
})
|
|
|
|
const backendRes = await fetch(backendReq)
|
|
|
|
// Forward Set-Cookie headers
|
|
const setCookies = backendRes.headers.get('set-cookie')
|
|
const responseHeaders = new Headers(backendRes.headers)
|
|
|
|
if (setCookies) {
|
|
responseHeaders.set('set-cookie', setCookies)
|
|
}
|
|
|
|
return new Response(backendRes.body, {
|
|
status: backendRes.status,
|
|
statusText: backendRes.statusText,
|
|
headers: responseHeaders,
|
|
})
|
|
}
|
|
|
|
// Serve static files from public directory
|
|
if (url.pathname !== '/' && !url.pathname.includes('.')) {
|
|
// SPA routing - serve index.html for all non-file routes
|
|
return new Response(index, {
|
|
headers: {
|
|
'Content-Type': 'text/html',
|
|
},
|
|
})
|
|
}
|
|
|
|
// Serve index.html for root
|
|
if (url.pathname === '/') {
|
|
return new Response(index, {
|
|
headers: {
|
|
'Content-Type': 'text/html',
|
|
},
|
|
})
|
|
}
|
|
|
|
// Let Bun handle other static files
|
|
return new Response('Not Found', { status: 404 })
|
|
},
|
|
development: {
|
|
hmr: true,
|
|
},
|
|
})
|
|
|
|
console.log(`Frontend server running on http://localhost:${PORT}`)
|
|
console.log(`Proxying API requests to ${BACKEND_URL}`)
|