diff --git a/resources/views/coolify.html b/resources/views/coolify.html
index 6b8a45e..c9754c0 100644
--- a/resources/views/coolify.html
+++ b/resources/views/coolify.html
@@ -1003,13 +1003,27 @@ document.addEventListener('alpine:init', () => {
}
},
- openInstModal(cfg = null) {
+ async openInstModal(cfg = null) {
this.instMsg = '';
- this.instEditId = cfg ? (cfg.ID || cfg.id) : null;
- this.instForm = cfg
- ? { nombre: cfg.Nombre || cfg.nombre || '', base_url: cfg.BaseURL || cfg.base_url || '', api_token: '', activo: cfg.Activo ?? cfg.activo ?? true }
- : { nombre: '', base_url: '', api_token: '', activo: true };
+ if (!cfg) {
+ this.instEditId = null;
+ this.instForm = { nombre: '', base_url: '', api_token: '', activo: true };
+ this.instModal = true;
+ return;
+ }
+ const id = cfg.ID || cfg.id;
+ this.instEditId = id;
+ // Valores locales como fallback mientras carga
+ this.instForm = { nombre: cfg.Nombre || cfg.nombre || '', base_url: cfg.BaseURL || cfg.base_url || '', api_token: '', activo: cfg.Activo ?? cfg.activo ?? true };
this.instModal = true;
+ // Refresco desde el server para garantizar datos actualizados
+ try {
+ const r = await fetch(`/app/coolify/configs/${id}`);
+ if (r.ok) {
+ const j = await r.json();
+ this.instForm = { nombre: j.nombre || '', base_url: j.base_url || '', api_token: '', activo: j.activo ?? true };
+ }
+ } catch(_) {}
},
async saveInst() {
diff --git a/rest/controllers/coolify_controller.go b/rest/controllers/coolify_controller.go
index 82d7398..749d5a5 100644
--- a/rest/controllers/coolify_controller.go
+++ b/rest/controllers/coolify_controller.go
@@ -500,6 +500,23 @@ func CoolifyListConfigs(c *fiber.Ctx) error {
return c.JSON(fiber.Map{"items": out})
}
+func CoolifyGetConfigByID(c *fiber.Ctx) error {
+ id, err := strconv.ParseUint(c.Params("id"), 10, 32)
+ if err != nil {
+ return c.Status(400).JSON(fiber.Map{"error": "id inválido"})
+ }
+ cfg, err := models.GetCoolifyConfigByID(uint(id))
+ if err != nil {
+ return c.Status(404).JSON(fiber.Map{"error": "instancia no encontrada"})
+ }
+ return c.JSON(fiber.Map{
+ "id": cfg.ID,
+ "nombre": cfg.Nombre,
+ "base_url": cfg.BaseURL,
+ "activo": cfg.Activo,
+ })
+}
+
func CoolifyCreateConfig(c *fiber.Ctx) error {
type Req struct {
Nombre string `json:"nombre"`
@@ -538,6 +555,9 @@ func CoolifyUpdateConfig(c *fiber.Ctx) error {
return c.Status(400).JSON(fiber.Map{"error": "body inválido"})
}
req.BaseURL = strings.TrimRight(strings.TrimSpace(req.BaseURL), "/")
+ if req.BaseURL == "" {
+ return c.Status(400).JSON(fiber.Map{"error": "base_url es requerido"})
+ }
cfg, err := models.UpdateCoolifyConfig(uint(id), req.Nombre, req.BaseURL, req.ApiToken, req.Activo)
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
diff --git a/rest/routes/user.go b/rest/routes/user.go
index 2381d49..03eadf4 100755
--- a/rest/routes/user.go
+++ b/rest/routes/user.go
@@ -195,6 +195,7 @@ func UserRoutes(app fiber.Router) {
// Gestión de instancias Coolify (multi-instancia)
protected.Get("/coolify/configs", controllers.CoolifyListConfigs)
protected.Post("/coolify/configs", controllers.CoolifyCreateConfig)
+ protected.Get("/coolify/configs/:id", controllers.CoolifyGetConfigByID)
protected.Put("/coolify/configs/:id", controllers.CoolifyUpdateConfig)
protected.Delete("/coolify/configs/:id", controllers.CoolifyDeleteConfig)
protected.Get("/coolify/configs/:id/test", controllers.CoolifyTestConfig)