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 ns2.auth.example.org.",
|
||||
]
|
||||
# debug messages from CORS etc
|
||||
debug = false
|
||||
|
||||
|
||||
[api]
|
||||
@ -24,11 +26,15 @@ records = [
|
||||
api_domain = ""
|
||||
# listen port, eg. 443 for default HTTPS
|
||||
port = "8080"
|
||||
# possible values: "letsencrypt", "cert", "false"
|
||||
tls = "letsencrypt"
|
||||
# possible values: "letsencrypt", "cert", "none"
|
||||
tls = "none"
|
||||
# only used if tls = "cert"
|
||||
tls_cert_privkey = "/etc/tls/example.org/privkey.pem"
|
||||
tls_cert_fullchain = "/etc/tls/example.org/fullchain.pem"
|
||||
# CORS AllowOrigins, wildcards can be used
|
||||
corsorigins = [
|
||||
"web.example.org"
|
||||
]
|
||||
|
||||
[logconfig]
|
||||
# logging level
|
||||
|
||||
9
main.go
9
main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/iris-contrib/middleware/cors"
|
||||
"github.com/kataras/iris"
|
||||
"github.com/miekg/dns"
|
||||
"github.com/op/go-logging"
|
||||
@ -81,6 +82,13 @@ func main() {
|
||||
|
||||
// API server and endpoints
|
||||
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{}
|
||||
api.Get("/register", WebRegisterGet)
|
||||
api.Post("/register", WebRegisterPost)
|
||||
@ -93,7 +101,6 @@ func main() {
|
||||
case "cert":
|
||||
host := DnsConf.Api.Domain + ":" + DnsConf.Api.Port
|
||||
api.ListenTLS(host, DnsConf.Api.Tls_cert_fullchain, DnsConf.Api.Tls_cert_privkey)
|
||||
|
||||
default:
|
||||
host := DnsConf.Api.Domain + ":" + DnsConf.Api.Port
|
||||
api.Listen(host)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user