From f4ecbe3e28d2c660b3adf2f8acde9ae9f07e8c14 Mon Sep 17 00:00:00 2001 From: joerivrij Date: Mon, 15 May 2023 09:13:26 +0200 Subject: [PATCH] Adds const --- api/router.go | 2 +- api/v1/const.go | 7 +++++++ api/v1/resultaat.go | 11 +++-------- 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 api/v1/const.go diff --git a/api/router.go b/api/router.go index 3470544..df1a643 100644 --- a/api/router.go +++ b/api/router.go @@ -15,7 +15,7 @@ func InitRoutes(loader *models.Loader) *mux.Router { Data: loader, } - serveMux.HandleFunc("/api/v1/health", middleware.Adapt(v1Handler.Health, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders())) + serveMux.HandleFunc("/api/v1/health", middleware.Adapt(v1Handler.Health, middleware.ValidateRestMethod("GET"), middleware.SetCorsHeaders())) //resultaten serveMux.HandleFunc("/api/v1/resultaten", middleware.Adapt(v1Handler.ListResultaten, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders())) diff --git a/api/v1/const.go b/api/v1/const.go new file mode 100644 index 0000000..2859e31 --- /dev/null +++ b/api/v1/const.go @@ -0,0 +1,7 @@ +package v1 + +const ( + productionHostName string = "referentielijsten-api.vng.cloud" + // currently we do not have a test server but this is for future proofing + testHostName string = "referentielijsten-api.test.vng.cloud" +) diff --git a/api/v1/resultaat.go b/api/v1/resultaat.go index e9736b0..78b8b41 100644 --- a/api/v1/resultaat.go +++ b/api/v1/resultaat.go @@ -51,9 +51,9 @@ func (r *ReferentielijstenHandler) ListResultaten(w http.ResponseWriter, req *ht // 404: Fout // 405: Fout - scheme := "https://" - if req.TLS == nil { - scheme = "http://" + scheme := "http://" + if req.TLS != nil || req.Host == productionHostName || req.Host == testHostName { + scheme = "https://" } log.Printf("req.TLS: %v", req.TLS) @@ -148,11 +148,6 @@ func (r *ReferentielijstenHandler) ListResultaten(w http.ResponseWriter, req *ht resultsToBeUsed := r.Data.Resultaten[start:finish] - log.Printf("scheme: %v", scheme) - log.Printf("req.Host: %v", req.Host) - log.Printf("req.URL.Path: %v", req.URL.Path) - log.Printf("req.Proto: %v", req.Proto) - for _, result := range resultsToBeUsed { u, _ := url.JoinPath(scheme, req.Host, req.URL.Path, result.URL) result.URL = u