import express from 'express';
import cors from 'cors';
import { env } from './env.js';
import listings from './routes/listings.js';
import { prisma } from './prisma.js';

const app = express();
app.use(cors());
app.use(express.json());

app.get('/health', async (_req, res) => {
  try {
    await prisma.$queryRaw`SELECT 1`;
    res.json({ ok: true });
  } catch (e) {
    res.status(500).json({ ok: false });
  }
});

app.use('/listings', listings);

app.listen(env.PORT, () => {
  console.log(`API on :${env.PORT}`);
});