All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m28s
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/quic-go/quic-go/http3"
|
|
"golang.org/x/crypto/acme/autocert"
|
|
)
|
|
|
|
func main() {
|
|
certManager := autocert.Manager{
|
|
Prompt: autocert.AcceptTOS,
|
|
HostPolicy: autocert.HostWhitelist("qgo-server.quizer.space"),
|
|
Cache: autocert.DirCache("certs"),
|
|
}
|
|
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/api/hello", func(w http.ResponseWriter, r *http.Request) {
|
|
// CORS
|
|
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:5173") // Или твой фронт домен
|
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
|
w.Header().Set("Alt-Svc", `h3=":443"; ma=86400`)
|
|
|
|
fmt.Printf("Запрос: %s | Протокол: %s\n", r.URL.Path, r.Proto)
|
|
w.Write([]byte(`{"message": "QUIC + Let's Encrypt работают!"}`))
|
|
})
|
|
|
|
// Стандартный TLS конфиг от autocert
|
|
tlsConfig := certManager.TLSConfig()
|
|
tlsConfig.NextProtos = []string{"h3", "h3-29", "h2", "http/1.1"}
|
|
|
|
// 1. Порт 80 для Let's Encrypt (обязательно)
|
|
go http.ListenAndServe(":80", certManager.HTTPHandler(nil))
|
|
|
|
// 2. HTTP/3 (UDP) на 443
|
|
go func() {
|
|
server := &http3.Server{
|
|
Addr: ":443",
|
|
Handler: mux,
|
|
TLSConfig: tlsConfig,
|
|
}
|
|
fmt.Println("Запуск QUIC (UDP) на 443...")
|
|
server.ListenAndServe()
|
|
}()
|
|
|
|
// 3. HTTPS (TCP) на 443
|
|
fmt.Println("Запуск HTTPS (TCP) на 443...")
|
|
server := &http.Server{
|
|
Addr: ":443",
|
|
Handler: mux,
|
|
TLSConfig: tlsConfig,
|
|
}
|
|
server.ListenAndServeTLS("", "")
|
|
}
|