mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-09 10:41:39 +08:00
Improve the setup database
This commit is contained in:
@@ -5,6 +5,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const Database = require("./database");
|
||||
const { allowDevAllOrigin } = require("./util-server");
|
||||
const mysql = require("mysql2/promise");
|
||||
|
||||
/**
|
||||
* A standalone express app that is used to setup database
|
||||
@@ -145,6 +146,7 @@ class SetupDatabase {
|
||||
return;
|
||||
}
|
||||
|
||||
// External MariaDB
|
||||
if (dbConfig.type === "mariadb") {
|
||||
if (!dbConfig.hostname) {
|
||||
response.status(400).json("Hostname is required");
|
||||
@@ -175,6 +177,22 @@ class SetupDatabase {
|
||||
this.runningSetup = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Test connection
|
||||
try {
|
||||
const connection = await mysql.createConnection({
|
||||
host: dbConfig.hostname,
|
||||
port: dbConfig.port,
|
||||
user: dbConfig.username,
|
||||
password: dbConfig.password,
|
||||
});
|
||||
await connection.execute("SELECT 1");
|
||||
connection.end();
|
||||
} catch (e) {
|
||||
response.status(400).json("Cannot connect to the database: " + e.message);
|
||||
this.runningSetup = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Write db-config.json
|
||||
|
Reference in New Issue
Block a user