- Add build-time data fetching from Confluence - Create build-data.js script to fetch and save data at build time - Update App.tsx to use static JSON in production, API in development - Install tsx for running TypeScript build scripts - Configure Amplify to fetch data during build process - Add public directory configuration to Vite This fixes the white page error by providing data at build time instead of runtime. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { defineConfig, loadEnv } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
// Dynamic import to avoid TypeScript issues
|
|
async function getConfluenceData(env: any) {
|
|
const { fetchFromConfluence } = await import('./src/server/confluence.js')
|
|
return fetchFromConfluence(env)
|
|
}
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
return {
|
|
publicDir: 'public',
|
|
plugins: [
|
|
react(),
|
|
{
|
|
name: 'api-middleware',
|
|
configureServer(server) {
|
|
server.middlewares.use('/api/filaments', async (req, res, next) => {
|
|
if (req.method !== 'GET') {
|
|
res.statusCode = 405
|
|
res.end('Method not allowed')
|
|
return
|
|
}
|
|
|
|
try {
|
|
const filaments = await getConfluenceData(env)
|
|
res.setHeader('Content-Type', 'application/json')
|
|
res.setHeader('Cache-Control', 'max-age=300')
|
|
res.end(JSON.stringify(filaments))
|
|
} catch (error) {
|
|
console.error('API Error:', error)
|
|
res.statusCode = 500
|
|
res.setHeader('Content-Type', 'application/json')
|
|
res.end(JSON.stringify({
|
|
error: 'Failed to fetch filaments',
|
|
message: error instanceof Error ? error.message : 'Unknown error'
|
|
}))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}) |