2019-06-02 15:33:44 +00:00
|
|
|
package gateway
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Swagger directory for the runtime files provided by bazel data.
|
|
|
|
const swaggerDir = "proto/beacon/rpc/v1/"
|
|
|
|
|
|
|
|
// SwaggerServer returns swagger specification files located under "/swagger/"
|
|
|
|
func SwaggerServer() http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !strings.HasSuffix(r.URL.Path, ".swagger.json") {
|
2019-10-01 20:05:17 +00:00
|
|
|
log.Debugf("Not found: %s", r.URL.Path)
|
2019-06-02 15:33:44 +00:00
|
|
|
http.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debugf("Serving %s\n", r.URL.Path)
|
|
|
|
p := strings.TrimPrefix(r.URL.Path, "/swagger/")
|
|
|
|
p = path.Join(swaggerDir, p)
|
|
|
|
http.ServeFile(w, r, p)
|
|
|
|
}
|
|
|
|
}
|