import express from 'express';
import cors from 'cors';
import contextRouter from './routes/context.js';

const app = express();

app.use(cors({ origin: true }));
const PORT = parseInt(process.env.PORT ?? '3015', 10);

app.use(express.json({ limit: '1mb' }));

app.use('/api', contextRouter);

app.get('/health', (_, res) => res.json({ status: 'ok', service: 'geo-device-svc' }));
app.get('/ready', (_, res) => res.json({ status: 'ready' }));

app.listen(PORT, '0.0.0.0', () => {
  console.log(`geo-device-svc listening on :${PORT}`);
  console.log(`  Context (GET):  /api/context`);
  console.log(`  Context (POST): /api/context (with client data in body)`);
});
