Added CORS support
This commit is contained in:
parent
9b452f69ff
commit
c1277e1aa3
10
config.cfg
10
config.cfg
@ -16,6 +16,8 @@ records = [
|
|||||||
"auth.example.org. NS ns1.auth.example.org.",
|
"auth.example.org. NS ns1.auth.example.org.",
|
||||||
"auth.example.org. NS ns2.auth.example.org.",
|
"auth.example.org. NS ns2.auth.example.org.",
|
||||||
]
|
]
|
||||||
|
# debug messages from CORS etc
|
||||||
|
debug = false
|
||||||
|
|
||||||
|
|
||||||
[api]
|
[api]
|
||||||
@ -24,11 +26,15 @@ records = [
|
|||||||
api_domain = ""
|
api_domain = ""
|
||||||
# listen port, eg. 443 for default HTTPS
|
# listen port, eg. 443 for default HTTPS
|
||||||
port = "8080"
|
port = "8080"
|
||||||
# possible values: "letsencrypt", "cert", "false"
|
# possible values: "letsencrypt", "cert", "none"
|
||||||
tls = "letsencrypt"
|
tls = "none"
|
||||||
# only used if tls = "cert"
|
# only used if tls = "cert"
|
||||||
tls_cert_privkey = "/etc/tls/example.org/privkey.pem"
|
tls_cert_privkey = "/etc/tls/example.org/privkey.pem"
|
||||||
tls_cert_fullchain = "/etc/tls/example.org/fullchain.pem"
|
tls_cert_fullchain = "/etc/tls/example.org/fullchain.pem"
|
||||||
|
# CORS AllowOrigins, wildcards can be used
|
||||||
|
corsorigins = [
|
||||||
|
"web.example.org"
|
||||||
|
]
|
||||||
|
|
||||||
[logconfig]
|
[logconfig]
|
||||||
# logging level
|
# logging level
|
||||||
|
|||||||
9
main.go
9
main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/iris-contrib/middleware/cors"
|
||||||
"github.com/kataras/iris"
|
"github.com/kataras/iris"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
@ -81,6 +82,13 @@ func main() {
|
|||||||
|
|
||||||
// API server and endpoints
|
// API server and endpoints
|
||||||
api := iris.New()
|
api := iris.New()
|
||||||
|
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 = AuthMiddleware{}
|
var ForceAuth AuthMiddleware = AuthMiddleware{}
|
||||||
api.Get("/register", WebRegisterGet)
|
api.Get("/register", WebRegisterGet)
|
||||||
api.Post("/register", WebRegisterPost)
|
api.Post("/register", WebRegisterPost)
|
||||||
@ -93,7 +101,6 @@ func main() {
|
|||||||
case "cert":
|
case "cert":
|
||||||
host := DnsConf.Api.Domain + ":" + DnsConf.Api.Port
|
host := DnsConf.Api.Domain + ":" + DnsConf.Api.Port
|
||||||
api.ListenTLS(host, DnsConf.Api.Tls_cert_fullchain, DnsConf.Api.Tls_cert_privkey)
|
api.ListenTLS(host, DnsConf.Api.Tls_cert_fullchain, DnsConf.Api.Tls_cert_privkey)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
host := DnsConf.Api.Domain + ":" + DnsConf.Api.Port
|
host := DnsConf.Api.Domain + ":" + DnsConf.Api.Port
|
||||||
api.Listen(host)
|
api.Listen(host)
|
||||||
|
|||||||
2
types.go
2
types.go
@ -26,6 +26,7 @@ type general struct {
|
|||||||
Domain string
|
Domain string
|
||||||
Nsname string
|
Nsname string
|
||||||
Nsadmin string
|
Nsadmin string
|
||||||
|
Debug bool
|
||||||
StaticRecords []string `toml:"records"`
|
StaticRecords []string `toml:"records"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ type httpapi struct {
|
|||||||
Tls string
|
Tls string
|
||||||
Tls_cert_privkey string
|
Tls_cert_privkey string
|
||||||
Tls_cert_fullchain string
|
Tls_cert_fullchain string
|
||||||
|
CorsOrigins []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logging config
|
// Logging config
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user