fix: editar instancia Coolify trae URL fresca del server y valida base_url no vacio
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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()})
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user