[release] v0.14.0-unstable10

This commit is contained in:
Yann Stepienik
2024-01-28 14:54:34 +00:00
parent 0b63ded805
commit 80bc5a7a50
3 changed files with 19 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "cosmos-server",
"version": "0.14.0-unstable9",
"version": "0.14.0-unstable10",
"description": "",
"main": "test-server.js",
"bugs": {

View File

@@ -11,6 +11,7 @@ import (
"github.com/azukaar/cosmos-server/src/docker"
)
func StatusRoute(w http.ResponseWriter, req *http.Request) {
config := utils.GetMainConfig()
@@ -20,17 +21,16 @@ func StatusRoute(w http.ResponseWriter, req *http.Request) {
if(req.Method == "GET") {
utils.Log("API: Status")
databaseStatus := true
if(!config.DisableUserManagement) {
err := utils.DB()
if err != nil {
utils.Error("Status: Database error", err)
databaseStatus = false
if config.NewInstall {
if(!config.DisableUserManagement) {
err := utils.DB()
if err != nil {
utils.Error("Status: Database error", err)
}
} else {
utils.Log("Status: User management is disabled, skipping database check")
}
} else {
utils.Log("Status: User management is disabled, skipping database check")
}
if(!docker.DockerIsConnected) {
@@ -53,7 +53,7 @@ func StatusRoute(w http.ResponseWriter, req *http.Request) {
// "network": utils.GetNetworkUsage(),
},
"hostmode": utils.IsHostNetwork || os.Getenv("HOSTNAME") == "",
"database": databaseStatus,
"database": utils.DBStatus,
"docker": docker.DockerIsConnected,
"backup_status": docker.ExportError,
"letsencrypt": utils.GetMainConfig().HTTPConfig.HTTPSCertificateMode == "LETSENCRYPT" && utils.GetMainConfig().HTTPConfig.SSLEmail == "",

View File

@@ -20,17 +20,20 @@ import (
var client *mongo.Client
var DBContainerName string
var DBStatus bool
func DB() error {
config := GetMainConfig()
if(config.DisableUserManagement) {
DBStatus = false
return errors.New("User Management is disabled")
}
mongoURL := config.MongoDB
if(client != nil && client.Ping(context.TODO(), readpref.Primary()) == nil) {
DBStatus = true
return nil
}
@@ -49,6 +52,7 @@ func DB() error {
}
if mongoURL == "" {
DBStatus = false
return errors.New("MongoDB URL is not set, cannot connect to the database.")
}
@@ -88,18 +92,20 @@ func DB() error {
client, err = mongo.Connect(context.TODO(), opts)
if err != nil {
DBStatus = false
return err
}
defer func() {
}()
// Ping the primary
if err := client.Ping(context.TODO(), readpref.Primary()); err != nil {
DBStatus = false
return err
}
initDB()
DBStatus = true
Log("Successfully connected to the database.")
return nil
}