Skip to content

Commit

Permalink
Merge pull request #7 from VNG-Realisatie/issue/#104-bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes reported in #104
  • Loading branch information
joerivrij authored May 15, 2023
2 parents 95f49b7 + 6c8de4d commit ba3216d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
11 changes: 3 additions & 8 deletions api/v1/procestype.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ func (r *ReferentielijstenHandler) ListProcesTypen(w http.ResponseWriter, req *h
var parsedYear int32

var response models.ProcesTypen
scheme := "https://"
if req.TLS == nil {
scheme = "http://"
}

scheme := getScheme(req)

if year != "" {
convertedYear, err := strconv.Atoi(year)
Expand Down Expand Up @@ -132,10 +130,7 @@ func (r *ReferentielijstenHandler) GetProcesType(w http.ResponseWriter, req *htt

pathParams := mux.Vars(req)
uuid := pathParams[UUIDFromParam]
scheme := "https://"
if req.TLS == nil {
scheme = "http://"
}
scheme := getScheme(req)

for _, result := range r.Data.ProcesTypen {
if result.URL == uuid {
Expand Down
13 changes: 5 additions & 8 deletions api/v1/resultaat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/VNG-Realisatie/referentielijsten-api/models"
"github.com/VNG-Realisatie/referentielijsten-api/validator"
"github.com/gorilla/mux"
"log"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -50,10 +51,9 @@ func (r *ReferentielijstenHandler) ListResultaten(w http.ResponseWriter, req *ht
// 404: Fout
// 405: Fout

scheme := "https://"
if req.TLS == nil {
scheme = "http://"
}
scheme := getScheme(req)

log.Printf("req.TLS: %v", req.TLS)

pageId := req.URL.Query().Get(PageFromParam)
procesType := req.URL.Query().Get(ProcesTypeFromParam)
Expand Down Expand Up @@ -200,10 +200,7 @@ func (r *ReferentielijstenHandler) GetResultaat(w http.ResponseWriter, req *http

pathParams := mux.Vars(req)
uuid := pathParams[UUIDFromParam]
scheme := "https://"
if req.TLS == nil {
scheme = "http://"
}
scheme := getScheme(req)

for _, result := range r.Data.Resultaten {
if result.URL == uuid {
Expand Down
10 changes: 2 additions & 8 deletions api/v1/resultaattypeomschrijving.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ func (r *ReferentielijstenHandler) ListResultaattypeomschrijvingen(w http.Respon
// 200: ResultaattypeOmschrijvingGeneriek
// 405: Fout

scheme := "https://"
if req.TLS == nil {
scheme = "http://"
}
scheme := getScheme(req)

//TODO remove
log.Print(req)
Expand Down Expand Up @@ -81,10 +78,7 @@ func (r *ReferentielijstenHandler) GetResultaattypeomschrijving(w http.ResponseW

pathParams := mux.Vars(req)
uuid := pathParams[UUIDFromParam]
scheme := "https://"
if req.TLS == nil {
scheme = "http://"
}
scheme := getScheme(req)

for _, result := range r.Data.ResultaattypenOmscrhijvingen {
if result.URL == uuid {
Expand Down
21 changes: 21 additions & 0 deletions api/v1/scheme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v1

import "net/http"

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

// getScheme determines the scheme used for building up a url
// currently the apis do not run on https -> they will always return http when running on kube
// for production this scheme should always be https
func getScheme(req *http.Request) string {
scheme := "http://"
if req.TLS != nil || req.Host == productionHostName || req.Host == testHostName {
scheme = "https://"
}

return scheme
}

0 comments on commit ba3216d

Please sign in to comment.