fix: enable TLS when WebAppURL is manually configured as HTTPS
The TLS certificate fetch was coupled inside the auto-detection block, so a manually configured https:// WebAppURL would skip cert loading entirely, causing the server to serve plain HTTP while Telegram expected HTTPS — resulting in a blank Mini App. Split URL resolution and TLS setup into separate steps so that any https:// URL (auto-detected or configured) triggers cert loading. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
dd8c3db2cf
commit
dbd9599913
1 changed files with 15 additions and 4 deletions
|
|
@ -274,7 +274,7 @@ func setupAndStartServices(
|
||||||
if cfg.Channels.Telegram.Enabled {
|
if cfg.Channels.Telegram.Enabled {
|
||||||
webAppURL := cfg.Channels.Telegram.WebAppURL
|
webAppURL := cfg.Channels.Telegram.WebAppURL
|
||||||
if webAppURL == "" {
|
if webAppURL == "" {
|
||||||
// Auto-detect Tailscale hostname and fetch TLS cert
|
// Auto-detect Tailscale hostname and build the WebAppURL
|
||||||
hostname, tsErr := tailscale.DetectHostname()
|
hostname, tsErr := tailscale.DetectHostname()
|
||||||
if tsErr != nil {
|
if tsErr != nil {
|
||||||
logger.InfoCF(
|
logger.InfoCF(
|
||||||
|
|
@ -282,15 +282,26 @@ func setupAndStartServices(
|
||||||
"Tailscale not available, Mini App disabled",
|
"Tailscale not available, Mini App disabled",
|
||||||
map[string]any{"error": tsErr.Error()},
|
map[string]any{"error": tsErr.Error()},
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
hostPort := net.JoinHostPort(hostname, strconv.Itoa(cfg.Gateway.Port))
|
||||||
|
webAppURL = "https://" + hostPort + "/miniapp"
|
||||||
|
cfg.Channels.Telegram.WebAppURL = webAppURL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// When the URL is HTTPS, fetch a TLS certificate from Tailscale so
|
||||||
|
// the server can actually serve over TLS. This covers both the
|
||||||
|
// auto-detected case above and a manually configured https:// URL.
|
||||||
|
if strings.HasPrefix(webAppURL, "https://") {
|
||||||
|
hostname, tsErr := tailscale.DetectHostname()
|
||||||
|
if tsErr != nil {
|
||||||
|
logger.ErrorCF("miniapp", "HTTPS URL configured but Tailscale not available", map[string]any{"error": tsErr.Error()})
|
||||||
} else {
|
} else {
|
||||||
certDir := filepath.Join(cfg.WorkspacePath(), "state", "certs")
|
certDir := filepath.Join(cfg.WorkspacePath(), "state", "certs")
|
||||||
certFile, keyFile, certErr := tailscale.FetchCert(hostname, certDir)
|
certFile, keyFile, certErr := tailscale.FetchCert(hostname, certDir)
|
||||||
if certErr != nil {
|
if certErr != nil {
|
||||||
logger.ErrorCF("miniapp", "Failed to fetch TLS cert", map[string]any{"error": certErr.Error()})
|
logger.ErrorCF("miniapp", "Failed to fetch TLS cert", map[string]any{"error": certErr.Error()})
|
||||||
} else {
|
} else {
|
||||||
hostPort := net.JoinHostPort(hostname, strconv.Itoa(cfg.Gateway.Port))
|
|
||||||
webAppURL = "https://" + hostPort + "/miniapp"
|
|
||||||
cfg.Channels.Telegram.WebAppURL = webAppURL
|
|
||||||
tlsCert, tlsKey = certFile, keyFile
|
tlsCert, tlsKey = certFile, keyFile
|
||||||
useTLS = true
|
useTLS = true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue