MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / openAPIServer

Function openAPIServer

examples/internal/gateway/handlers.go:18–31  ·  view source on GitHub ↗

openAPIServer returns OpenAPI specification files located under "/openapiv2/"

(dir string)

Source from the content-addressed store, hash-verified

16
17// openAPIServer returns OpenAPI specification files located under "/openapiv2/"
18func openAPIServer(dir string) http.HandlerFunc {
19 return func(w http.ResponseWriter, r *http.Request) {
20 if !strings.HasSuffix(r.URL.Path, ".swagger.json") {
21 grpclog.Errorf("Not Found: %s", r.URL.Path)
22 http.NotFound(w, r)
23 return
24 }
25
26 grpclog.Infof("Serving %s", r.URL.Path)
27 p := strings.TrimPrefix(r.URL.Path, "/openapiv2/")
28 p = path.Join(dir, p)
29 http.ServeFile(w, r, p)
30 }
31}
32
33// allowCORS allows Cross Origin Resource Sharing from any origin.
34// Don't do this without consideration in production systems.

Callers 1

RunFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected