import express from 'express'; import dotenv from 'dotenv'; import { batchInsert } from './batchInsertCall.js'; const app = express(); // Middleware to parse JSON bodies app.use(express.json()); dotenv.config({ path: '.env' }); // Health check endpoint app.get('/', (req, res) => { res.json({ status: 'OK', message: 'Batch insert Service is running', endpoints: { export: 'POST /batch-insert - Batch insert data to BQ' } }); }); app.post('/batch-insert', async (req, res) => { try { const result = await batchInsert(req, res); res.status(200).json(result); } 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}`); }); // For serverless functions (like Google Cloud Functions) export default app;