// FILE: backend/src/routes/health.js
import { Router } from "express";
import sql from "../db/index.js";

const r = Router();

// /api/health — ไม่ต้องใช้สิทธิ์
r.get("/health", async (_req, res) => {
  try {
    const [[{ now }]] = await sql.query("SELECT NOW() AS now");
    res.status(200).json({ ok: true, db: "up", now });
  } catch (e) {
    res
      .status(500)
      .json({ ok: false, db: "down", error: String(e?.message || e) });
  }
});

export default r;
