minor fix

This commit is contained in:
Anish Mukherjee 2022-12-13 11:08:53 +05:30
parent 9c019ca1b1
commit 72687b9a0f
3 changed files with 50 additions and 49 deletions

View file

@ -39,7 +39,7 @@ type ServerConfig struct {
MQHOST string `yaml:"mqhost"`
MasterKey string `yaml:"masterkey"`
DNSKey string `yaml:"dnskey"`
AllowedOrigin []string `yaml:"allowedorigin"`
AllowedOrigin string `yaml:"allowedorigin"`
NodeID string `yaml:"nodeid"`
RestBackend string `yaml:"restbackend"`
AgentBackend string `yaml:"agentbackend"`

View file

@ -6,6 +6,7 @@ import (
"net/http"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"
@ -38,7 +39,7 @@ func HandleRESTRequests(wg *sync.WaitGroup) {
// Currently allowed dev origin is all. Should change in prod
// should consider analyzing the allowed methods further
headersOk := handlers.AllowedHeaders([]string{"Access-Control-Allow-Origin", "X-Requested-With", "Content-Type", "authorization"})
originsOk := handlers.AllowedOrigins(servercfg.GetAllowedOrigin())
originsOk := handlers.AllowedOrigins(strings.Split(servercfg.GetAllowedOrigin(), ","))
methodsOk := handlers.AllowedMethods([]string{"GET", "PUT", "POST", "DELETE"})
for _, handler := range HttpHandlers {

View file

@ -267,11 +267,11 @@ func GetDNSKey() string {
}
// GetAllowedOrigin - get the allowed origin
func GetAllowedOrigin() []string {
allowedorigin := []string{"*"}
func GetAllowedOrigin() string {
allowedorigin := "*"
if os.Getenv("CORS_ALLOWED_ORIGIN") != "" {
allowedorigin = strings.Split(os.Getenv("CORS_ALLOWED_ORIGIN"), ",")
} else if len(config.Config.Server.AllowedOrigin) > 0 {
allowedorigin = os.Getenv("CORS_ALLOWED_ORIGIN")
} else if config.Config.Server.AllowedOrigin != "" {
allowedorigin = config.Config.Server.AllowedOrigin
}
return allowedorigin