| const { Pool } = require('pg'); | |
| module.exports = async (req, res) => { | |
| try { | |
| const { host, port, user, password, dbname, sslmode } = req.body; | |
| const pool = new Pool({ | |
| host, | |
| port, | |
| user, | |
| password, | |
| database: dbname, | |
| ssl: sslmode === 'require' ? { rejectUnauthorized: false } : false | |
| }); | |
| const client = await pool.connect(); | |
| const result = await client.query(` | |
| SELECT table_name, table_schema | |
| FROM information_schema.tables | |
| WHERE table_schema NOT IN ('pg_catalog', 'information_schema') | |
| `); | |
| client.release(); | |
| await pool.end(); | |
| res.status(200).json(result.rows); | |
| } catch (error) { | |
| console.error('Database error:', error); | |
| res.status(500).json({ error: 'Failed to fetch tables' }); | |
| } | |
| }; |