diff --git a/server/routes.go b/server/routes.go index 16f22cf93..8886073cf 100644 --- a/server/routes.go +++ b/server/routes.go @@ -1170,6 +1170,7 @@ func (s *Server) GenerateRoutes(rc *ollama.Registry) (http.Handler, error) { corsConfig.AllowOrigins = envconfig.AllowedOrigins() r := gin.Default() + r.HandleMethodNotAllowed = true r.Use( cors.New(corsConfig), allowedHostsMiddleware(s.addr), diff --git a/server/routes_test.go b/server/routes_test.go index 2894b1555..9859af653 100644 --- a/server/routes_test.go +++ b/server/routes_test.go @@ -485,6 +485,16 @@ func TestRoutes(t *testing.T) { } }, }, + { + Name: "Method Not Allowed", + Method: http.MethodGet, + Path: "/api/show", + Expected: func(t *testing.T, resp *http.Response) { + if resp.StatusCode != 405 { + t.Errorf("expected status code 405, got %d", resp.StatusCode) + } + }, + }, } modelsDir := t.TempDir()