Add error handling for cert failure

This commit is contained in:
Anders Pitman 2020-09-29 23:24:22 -06:00
parent 9bd415af50
commit 10f79beec6
2 changed files with 10 additions and 3 deletions

View File

@ -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)
}

View File

@ -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) {