From 5f11216cbf4abb245513e32628c5df367ac835d1 Mon Sep 17 00:00:00 2001 From: pablinux Date: Wed, 14 Oct 2026 07:54:29 -0500 Subject: [PATCH] feat: soportar proxy reverso dinamico y actualizar puerto 2006 de produccion --- .agente/infraestructura.md | 2 +- agents.md | 2 +- internal/handlers/handlers.go | 28 +++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.agente/infraestructura.md b/.agente/infraestructura.md index 9c8ab91..ee50581 100644 --- a/.agente/infraestructura.md +++ b/.agente/infraestructura.md @@ -1342,7 +1342,7 @@ Aplicación web en Go para transferencia inmediata de archivos, fotos, documento | Ubicación local | `siax-amd` — `/home/pablinux/Projects/GO/app_compartir` | | Servidor de producción | `server-webapps` CT 132 (`192.168.10.160`) — pendiente deploy | | Dominio público | `drop.sigmac.app` | -| Puerto | `8085` | +| Puerto | `2006` | | Servicio systemd | `app-compartir.service` | **Bases de Datos:** diff --git a/agents.md b/agents.md index 0a1f500..8ca6baa 100644 --- a/agents.md +++ b/agents.md @@ -74,7 +74,7 @@ Goroutine periódica (ticker) que consulta items donde `is_guest = true AND expi | Parámetro | Valor | |---|---| | Dominio público | `drop.sigmac.app` | -| Puerto interno | `8085` (o configurable vía `PORT`) | +| Puerto interno | `2006` (producción) / `8085` (local) | | Servicio systemd | `app-compartir.service` | | BD principal | SQLite local (`data/compartir.db`) | | MCP ecosistema | `mcp.telcotronics.net` 🔧 en mantenimiento | diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 27e6dd0..1ef89a2 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -70,6 +70,21 @@ type PageData struct { Error string } +func (h *Handlers) getBaseURL(r *http.Request) string { + proto := "http" + if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" { + proto = "https" + } + host := r.Host + if host == "" { + host = r.Header.Get("X-Forwarded-Host") + } + if host != "" { + return fmt.Sprintf("%s://%s", proto, host) + } + return h.cfg.BaseURL +} + func (h *Handlers) Index(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { http.NotFound(w, r) @@ -164,14 +179,15 @@ func (h *Handlers) Upload(w http.ResponseWriter, r *http.Request) { return } + baseURL := h.getBaseURL(r) resp := map[string]interface{}{ "id": share.ID, "title": share.Title, "file_size": share.FileSize, "mime_type": share.MimeType, "is_guest": share.IsGuest, - "viewer_url": fmt.Sprintf("%s/v/%s", h.cfg.BaseURL, share.ID), - "download_url": fmt.Sprintf("%s/d/%s", h.cfg.BaseURL, share.ID), + "viewer_url": fmt.Sprintf("%s/v/%s", baseURL, share.ID), + "download_url": fmt.Sprintf("%s/d/%s", baseURL, share.ID), } if share.IsGuest { resp["expires_in"] = "24 horas" @@ -258,14 +274,15 @@ func (h *Handlers) ShareText(w http.ResponseWriter, r *http.Request) { return } + baseURL := h.getBaseURL(r) resp := map[string]interface{}{ "id": share.ID, "title": share.Title, "file_size": share.FileSize, "mime_type": share.MimeType, "is_guest": share.IsGuest, - "viewer_url": fmt.Sprintf("%s/v/%s", h.cfg.BaseURL, share.ID), - "download_url": fmt.Sprintf("%s/d/%s", h.cfg.BaseURL, share.ID), + "viewer_url": fmt.Sprintf("%s/v/%s", baseURL, share.ID), + "download_url": fmt.Sprintf("%s/d/%s", baseURL, share.ID), } if share.IsGuest { resp["expires_in"] = "24 horas" @@ -407,7 +424,8 @@ func (h *Handlers) QR(w http.ResponseWriter, r *http.Request) { return } - targetURL := fmt.Sprintf("%s/v/%s", h.cfg.BaseURL, id) + baseURL := h.getBaseURL(r) + targetURL := fmt.Sprintf("%s/v/%s", baseURL, id) pngBytes, err := qrcode.Encode(targetURL, qrcode.Medium, 256) if err != nil { http.Error(w, "Error generando QR", http.StatusInternalServerError)