Fix production data fetching with static JSON
- 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>
This commit is contained in:
35
scripts/build-data.js
Normal file
35
scripts/build-data.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { fetchFromConfluence } from '../src/server/confluence.ts';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
async function buildData() {
|
||||
try {
|
||||
console.log('Fetching filament data from Confluence...');
|
||||
const filaments = await fetchFromConfluence({
|
||||
CONFLUENCE_API_URL: process.env.CONFLUENCE_API_URL,
|
||||
CONFLUENCE_TOKEN: process.env.CONFLUENCE_TOKEN,
|
||||
CONFLUENCE_PAGE_ID: process.env.CONFLUENCE_PAGE_ID
|
||||
});
|
||||
|
||||
// Create public directory if it doesn't exist
|
||||
const publicDir = path.join(__dirname, '..', 'public');
|
||||
if (!fs.existsSync(publicDir)) {
|
||||
fs.mkdirSync(publicDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Write data to public directory
|
||||
const dataPath = path.join(publicDir, 'filaments.json');
|
||||
fs.writeFileSync(dataPath, JSON.stringify(filaments, null, 2));
|
||||
|
||||
console.log(`Successfully wrote ${filaments.length} filaments to ${dataPath}`);
|
||||
} catch (error) {
|
||||
console.error('Error building data:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
buildData();
|
||||
Reference in New Issue
Block a user