Commit cf8d4f2c authored by Mudassar Khan's avatar Mudassar Khan
Browse files

Merge branch 'STF_685_MEC_IPE' into STF_685

parents 4567a575 3728c704
Loading
Loading
Loading
Loading
+1 −1
Changes for go-apps/meep-ipe/Server/ipe_init.go: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ func StartServer(config map[string]interface{}) {
	addr := fmt.Sprintf(":%s", port)
	srv := &http.Server{
		Addr:    addr,
		Handler: handlers.CORS()(router),
		Handler: handlers.CORS()(CleanPath(router)),
	}

	// Run the server in a goroutine so it doesn't block signal handling
+23 −1
Changes for go-apps/meep-ipe/Server/router.go: 23 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -35,8 +35,30 @@ type HttpRoute struct {

type HttpRoutes []HttpRoute

// CleanPath normalizes the request path (e.g. "//meep_ipe/v1/..." -> "/meep_ipe/v1/...")
func CleanPath(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		p := r.URL.Path
		if p == "" {
			p = "/"
		}
		cleaned := path.Clean(p)
		// Keep the trailing slash, same as gorilla/mux cleanPath
		if strings.HasSuffix(p, "/") && cleaned != "/" {
			cleaned += "/"
		}
		if cleaned != r.URL.Path {
			log.Printf("CleanPath: rewriting '%s' to '%s'", r.URL.Path, cleaned)
			r.URL.Path = cleaned
			r.URL.RawPath = ""
		}
		next.ServeHTTP(w, r)
	})
}

func NewRouter(config map[string]interface{}) *mux.Router {
	router := mux.NewRouter().StrictSlash(true)
	// No StrictSlash: its trailing slash redirect turns a POST into a GET as well
	router := mux.NewRouter()

	for _, route := range getRoutes(config) {
		fullPath := path.Join(route.Pattern)