mirror of
https://github.com/TwiN/gatus.git
synced 2025-05-31 15:16:01 +02:00
Add development CORS header when the "ENVIRONMENT" environment variable is set to "dev"
This commit is contained in:
parent
bc6ca2ebd0
commit
f1aa5191bf
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -34,7 +35,10 @@ func init() {
|
|||||||
// Handle creates the router and starts the server
|
// Handle creates the router and starts the server
|
||||||
func Handle() {
|
func Handle() {
|
||||||
cfg := config.Get()
|
cfg := config.Get()
|
||||||
router := CreateRouter(cfg)
|
var router http.Handler = CreateRouter(cfg)
|
||||||
|
if os.Getenv("ENVIRONMENT") == "dev" {
|
||||||
|
router = developmentCorsHandler(router)
|
||||||
|
}
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", cfg.Web.Address, cfg.Web.Port),
|
Addr: fmt.Sprintf("%s:%d", cfg.Web.Address, cfg.Web.Port),
|
||||||
Handler: router,
|
Handler: router,
|
||||||
|
10
controller/cors.go
Normal file
10
controller/cors.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func developmentCorsHandler(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:8081")
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user