Skip to content

Commit

Permalink
Remove the certmagic
Browse files Browse the repository at this point in the history
  • Loading branch information
thesoulless committed Dec 23, 2024
1 parent b34a64b commit 35131a5
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"context"
"crypto/tls"
"embed"
"encoding/gob"
Expand All @@ -15,7 +14,6 @@ import (
"strings"
"time"

"github.com/caddyserver/certmagic"
"github.com/go-chi/chi/v5"
"github.com/rs/xid"
"golang.org/x/exp/slog"
Expand Down Expand Up @@ -104,39 +102,6 @@ func setupServer(mux http.Handler) (*http.Server, error) {
MaxHeaderBytes: 1 << 12,
}

if cert == "" && certKey == "" {
domains := strings.Split(domain, ",")

ca := certmagic.LetsEncryptStagingCA

if !dev {
ca = certmagic.LetsEncryptProductionCA
}

magic := certmagic.NewDefault()
issuer := certmagic.NewACMEIssuer(magic, certmagic.ACMEIssuer{
CA: ca,
Email: email,
Agreed: true,
})
magic.Issuers = []certmagic.Issuer{issuer}

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

err := magic.ManageSync(ctx, domains)
if err != nil {
return nil, fmt.Errorf("magic.ManageSync: %w", err)
}

tlsConfig := magic.TLSConfig()

tlsConfig.NextProtos = append([]string{"h2", "http/1.1"}, tlsConfig.NextProtos...)

srv.Handler = issuer.HTTPChallengeHandler(mux)
srv.TLSConfig = tlsConfig
}

if cert != "" && certKey != "" {
cer, err := tls.LoadX509KeyPair(cert, certKey)
if err != nil {
Expand Down

0 comments on commit 35131a5

Please sign in to comment.