mirror of
https://github.com/joohoi/acme-dns.git
synced 2025-01-05 13:08:06 +07:00
Moved HTTP server methods to main
This commit is contained in:
parent
ca13a4baeb
commit
74f160114b
32
main.go
32
main.go
@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/iris-contrib/middleware/cors"
|
||||||
|
"github.com/kataras/iris"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,3 +44,33 @@ func main() {
|
|||||||
|
|
||||||
log.Debugf("Shutting down...")
|
log.Debugf("Shutting down...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func startHTTPAPI() {
|
||||||
|
api := iris.New()
|
||||||
|
api.Config.DisableBanner = true
|
||||||
|
crs := cors.New(cors.Options{
|
||||||
|
AllowedOrigins: DNSConf.API.CorsOrigins,
|
||||||
|
AllowedMethods: []string{"GET", "POST"},
|
||||||
|
OptionsPassthrough: false,
|
||||||
|
Debug: DNSConf.General.Debug,
|
||||||
|
})
|
||||||
|
api.Use(crs)
|
||||||
|
var ForceAuth = authMiddleware{}
|
||||||
|
api.Get("/register", webRegisterGet)
|
||||||
|
api.Post("/register", webRegisterPost)
|
||||||
|
api.Post("/update", ForceAuth.Serve, webUpdatePost)
|
||||||
|
switch DNSConf.API.TLS {
|
||||||
|
case "letsencrypt":
|
||||||
|
listener, err := iris.LETSENCRYPTPROD(DNSConf.API.Domain)
|
||||||
|
err = api.Serve(listener)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Error in HTTP server [%v]", err)
|
||||||
|
}
|
||||||
|
case "cert":
|
||||||
|
host := DNSConf.API.Domain + ":" + DNSConf.API.Port
|
||||||
|
api.ListenTLS(host, DNSConf.API.TLSCertFullchain, DNSConf.API.TLSCertPrivkey)
|
||||||
|
default:
|
||||||
|
host := DNSConf.API.Domain + ":" + DNSConf.API.Port
|
||||||
|
api.Listen(host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
32
util.go
32
util.go
@ -5,8 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/iris-contrib/middleware/cors"
|
|
||||||
"github.com/kataras/iris"
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/satori/go.uuid"
|
"github.com/satori/go.uuid"
|
||||||
"math/big"
|
"math/big"
|
||||||
@ -89,33 +87,3 @@ func startDNS(listen string) *dns.Server {
|
|||||||
}()
|
}()
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
|
|
||||||
func startHTTPAPI() {
|
|
||||||
api := iris.New()
|
|
||||||
api.Config.DisableBanner = true
|
|
||||||
crs := cors.New(cors.Options{
|
|
||||||
AllowedOrigins: DNSConf.API.CorsOrigins,
|
|
||||||
AllowedMethods: []string{"GET", "POST"},
|
|
||||||
OptionsPassthrough: false,
|
|
||||||
Debug: DNSConf.General.Debug,
|
|
||||||
})
|
|
||||||
api.Use(crs)
|
|
||||||
var ForceAuth = authMiddleware{}
|
|
||||||
api.Get("/register", webRegisterGet)
|
|
||||||
api.Post("/register", webRegisterPost)
|
|
||||||
api.Post("/update", ForceAuth.Serve, webUpdatePost)
|
|
||||||
switch DNSConf.API.TLS {
|
|
||||||
case "letsencrypt":
|
|
||||||
listener, err := iris.LETSENCRYPTPROD(DNSConf.API.Domain)
|
|
||||||
err = api.Serve(listener)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Error in HTTP server [%v]", err)
|
|
||||||
}
|
|
||||||
case "cert":
|
|
||||||
host := DNSConf.API.Domain + ":" + DNSConf.API.Port
|
|
||||||
api.ListenTLS(host, DNSConf.API.TLSCertFullchain, DNSConf.API.TLSCertPrivkey)
|
|
||||||
default:
|
|
||||||
host := DNSConf.API.Domain + ":" + DNSConf.API.Port
|
|
||||||
api.Listen(host)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user