diff --git a/boringproxy.go b/boringproxy.go index efbf464..a8ec18d 100644 --- a/boringproxy.go +++ b/boringproxy.go @@ -299,7 +299,12 @@ func (p *BoringProxy) handleCreateTunnel(w http.ResponseWriter, r *http.Request) return } - p.tunMan.SetTunnel(host, port) + err = p.tunMan.SetTunnel(host, port) + if err != nil { + w.WriteHeader(400) + io.WriteString(w, "Failed to get cert. Ensure your domain is valid") + return + } http.Redirect(w, r, "/", 303) } diff --git a/tunnel_manager.go b/tunnel_manager.go index 6949d70..9e500a9 100644 --- a/tunnel_manager.go +++ b/tunnel_manager.go @@ -53,11 +53,11 @@ func NewTunnelManager(certConfig *certmagic.Config) *TunnelManager { return &TunnelManager{tunnels, mutex, certConfig} } -func (m *TunnelManager) SetTunnel(host string, port int) { +func (m *TunnelManager) SetTunnel(host string, port int) error { err := m.certConfig.ManageSync([]string{host}) if err != nil { - log.Println("CertMagic error") log.Println(err) + return errors.New("Failed to get cert") } tunnel := &Tunnel{port} @@ -65,6 +65,8 @@ func (m *TunnelManager) SetTunnel(host string, port int) { m.tunnels[host] = tunnel saveJson(m.tunnels, "tunnels.json") m.mutex.Unlock() + + return nil } func (m *TunnelManager) DeleteTunnel(host string) {