Added CORS support

This commit is contained in:
Joona Hoikkala 2016-11-16 14:56:49 +02:00
parent 9b452f69ff
commit c1277e1aa3
No known key found for this signature in database
GPG Key ID: C14AAE0F5ADCB854
3 changed files with 18 additions and 3 deletions

View File

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

View File

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

View File

@ -26,6 +26,7 @@ type general struct {
Domain string
Nsname string
Nsadmin string
Debug bool
StaticRecords []string `toml:"records"`
}
@ -36,6 +37,7 @@ type httpapi struct {
Tls string
Tls_cert_privkey string
Tls_cert_fullchain string
CorsOrigins []string
}
// Logging config