(req: NextApiRequest, res: NextApiResponse)
| 8 | // req body: { connection: Connection } |
| 9 | // It's mainly used to test the connection. |
| 10 | const handler = async (req: NextApiRequest, res: NextApiResponse) => { |
| 11 | if (req.method !== "POST") { |
| 12 | return res.status(405).json(false); |
| 13 | } |
| 14 | |
| 15 | let connection = req.body.connection as Connection; |
| 16 | if (connection.engineType === Engine.TiDB) { |
| 17 | connection = changeTiDBConnectionToMySQL(connection); |
| 18 | } |
| 19 | try { |
| 20 | const connector = newConnector(connection); |
| 21 | await connector.testConnection(); |
| 22 | res.status(200).json({}); |
| 23 | } catch (error: any) { |
| 24 | res.status(400).json({ |
| 25 | message: error.message || "Failed to test connection.", |
| 26 | code: error.code || "UNKNOWN", |
| 27 | }); |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | export default handler; |
nothing calls this directly
no test coverage detected