Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rekor-server: add html page when humans reach the server via the browser #394

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/generated/restapi/configure_rekor_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"strconv"
"time"

// using embed to add the static html page duing build time
_ "embed"

"github.com/go-chi/chi/middleware"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
Expand Down Expand Up @@ -149,6 +152,7 @@ func setupGlobalMiddleware(handler http.Handler) http.Handler {
returnHandler := middleware.Logger(handler)
returnHandler = middleware.Recoverer(returnHandler)
returnHandler = middleware.Heartbeat("/ping")(returnHandler)
returnHandler = serveStaticContent(returnHandler)

handleCORS := cors.Default().Handler
returnHandler = handleCORS(returnHandler)
Expand Down Expand Up @@ -203,3 +207,18 @@ func logAndServeError(w http.ResponseWriter, r *http.Request, err error) {
}
errors.ServeError(w, r, err)
}

//go:embed rekorHomePage.html
var homePageBytes []byte

func serveStaticContent(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
w.Header().Add("Content-Type", "text/html")
w.WriteHeader(200)
_, _ = w.Write(homePageBytes)
return
}
handler.ServeHTTP(w, r)
})
}
30 changes: 30 additions & 0 deletions pkg/generated/restapi/rekorHomePage.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.