import express from 'express'; import { exportMergedJson } from './bqexport.js'; const app = express(); // Middleware to parse JSON bodies app.use(express.json()); // Health check endpoint app.get('/', (req, res) => { res.json({ status: 'OK', message: 'BigQuery Export Service is running', endpoints: { export: 'POST /export - Export BigQuery data to GCS' } }); }); app.post('/export', async (req, res) => { try { const { companyId, applicationId } = req.body; console.log(`Received export request:`); console.log(`Company ID: ${companyId}`); console.log(`Application ID: ${applicationId}`); // Call the BigQuery export function const result = await exportMergedJson(req, res); // Send success response res.status(200).json({ success: true, signedUrl: result.signedUrl, message: result.message, companyId: result.companyId, applicationId: result.applicationId, destination: result.destination }); } catch (error) { console.error('Export endpoint error:', error); res.status(500).json({ success: false, error: error.message }); } }); const PORT = process.env.PORT || 8080; app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });