/* Simple playground server: exposes /api/upload-managers which runs the run() exporter from run.js and returns the JSON result. Meant for local development. */ require('dotenv').config(); const express = require('express'); const cors = require('cors'); const bodyParser = require('body-parser'); const path = require('path'); const { run } = require('./run'); const app = express(); app.use(cors()); app.use(bodyParser.json()); // health app.get('/api/health', (req, res) => res.json({ ok: true, ts: new Date().toISOString() })); // main endpoint — run the uploader flow (download workbook if env vars exist, create folders and upload PDF) app.post('/api/upload-managers', async (req, res) => { try { const result = await run(); res.json({ ok: true, result }); } catch (err) { console.error('Error in /api/upload-managers', err); res.status(500).json({ ok: false, error: (err && err.message) ? err.message : String(err) }); } }); const port = process.env.PLAYGROUND_PORT || 3002; app.listen(port, () => console.log(`minimal-uploader-playground server listening on http://localhost:${port}`));