openAPIServer returns OpenAPI specification files located under "/openapiv2/"
(dir string)
| 16 | |
| 17 | // openAPIServer returns OpenAPI specification files located under "/openapiv2/" |
| 18 | func 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. |