1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24import type { NextApiHandler } from "next";
import { Pool, DatabaseError } from "pg";
const pool = new Pool({
connectionString: `postgres://postgres:postgres@localhost:5433/postgres`,
});
export interface Connection {
error: string | null;
}
const connectionApi: NextApiHandler<Connection> = async (req, res) => {
try {
await Promise.all([
pool.query("SELECT count(*) FROM thread"),
pool.query("SELECT count(*) FROM post"),
]);
res.status(200).json({ error: null });
} catch (error) {
res.status(200).json({ error: (error as DatabaseError).message });
}
};
export default connectionApi;