new quic release
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m27s
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m27s
This commit is contained in:
22
main.go
22
main.go
@@ -12,40 +12,40 @@ func main() {
|
|||||||
certManager := autocert.Manager{
|
certManager := autocert.Manager{
|
||||||
Prompt: autocert.AcceptTOS,
|
Prompt: autocert.AcceptTOS,
|
||||||
HostPolicy: autocert.HostWhitelist("qgo-server.quizer.space"),
|
HostPolicy: autocert.HostWhitelist("qgo-server.quizer.space"),
|
||||||
Cache: autocert.DirCache("certs"),
|
Cache: autocert.DirCache("certs"), // Папка для хранения сертификатов
|
||||||
}
|
}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/api/hello", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/api/hello", func(w http.ResponseWriter, r *http.Request) {
|
||||||
// CORS
|
// Сообщаем браузеру, что мы работаем на h3 на 443 порту
|
||||||
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`)
|
w.Header().Set("Alt-Svc", `h3=":443"; ma=86400`)
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
|
||||||
|
// Лог в консоль сервера, чтобы видеть реальный протокол
|
||||||
fmt.Printf("Запрос: %s | Протокол: %s\n", r.URL.Path, r.Proto)
|
fmt.Printf("Запрос: %s | Протокол: %s\n", r.URL.Path, r.Proto)
|
||||||
w.Write([]byte(`{"message": "QUIC + Let's Encrypt работают!"}`))
|
w.Write([]byte(fmt.Sprintf("Привет! Это честный QUIC. Протокол: %s", r.Proto)))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Стандартный TLS конфиг от autocert
|
// Настройка TLS для поддержки QUIC и ACME (Let's Encrypt)
|
||||||
tlsConfig := certManager.TLSConfig()
|
tlsConfig := certManager.TLSConfig()
|
||||||
tlsConfig.NextProtos = []string{"h3", "h3-29", "h2", "http/1.1"}
|
tlsConfig.NextProtos = []string{"h3", "h3-29", "h2", "http/1.1"}
|
||||||
|
|
||||||
// 1. Порт 80 для Let's Encrypt (обязательно)
|
// 1. Запуск проверки Let's Encrypt (порт 80)
|
||||||
go http.ListenAndServe(":80", certManager.HTTPHandler(nil))
|
go http.ListenAndServe(":80", certManager.HTTPHandler(nil))
|
||||||
|
|
||||||
// 2. HTTP/3 (UDP) на 443
|
// 2. Запуск QUIC (UDP)
|
||||||
go func() {
|
go func() {
|
||||||
server := &http3.Server{
|
server := &http3.Server{
|
||||||
Addr: ":443",
|
Addr: ":443",
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
TLSConfig: tlsConfig,
|
TLSConfig: tlsConfig,
|
||||||
}
|
}
|
||||||
fmt.Println("Запуск QUIC (UDP) на 443...")
|
fmt.Println("QUIC сервер слушает UDP :443")
|
||||||
server.ListenAndServe()
|
server.ListenAndServe()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// 3. HTTPS (TCP) на 443
|
// 3. Запуск HTTPS (TCP) - нужен для первого рукопожатия браузера
|
||||||
fmt.Println("Запуск HTTPS (TCP) на 443...")
|
fmt.Println("HTTPS сервер слушает TCP :443")
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: ":443",
|
Addr: ":443",
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
|
|||||||
Reference in New Issue
Block a user