prysm-pulse/validator/web/handler.go
james-prysm 394bd1786a
HTTP validator API: beacon and account endpoints (#13191)
* fixing squashing changes, migrates beacon , account, and auth endpoints on validator client

* adding accounts endpoints

* fixing tests and query endpoints

* adding auth endpoint and fixing unit tests

* removing unused files and updating node file to skip gRPC

* ineffectual assignment fix

* rolling back a change to fix e2e

* fixing issues with ui

* updating with webui version 2.0.5

* updating package name flag in readme

* removing restore assets functions

* adding nomemcopy flag to see if vulenerability scan passes

* making data non compressed to avoid copy vulnerability

* Update beacon-chain/rpc/eth/shared/structs_validator.go

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>

* updating site_data, and skipping static analysis on file

* adding back deprecation comment notice

* updating workflows to ignore generated

* addressing radek comments

* missed a conversion

---------

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2023-12-01 20:40:09 +00:00

59 lines
1.7 KiB
Go

package web
import (
"mime"
"net/http"
"net/url"
"path"
)
const prefix = "prysm-web-ui"
// Handler serves web requests from the bundled site data.
// DEPRECATED: Prysm Web UI and associated endpoints will be fully removed in a future hard fork.
var Handler = func(res http.ResponseWriter, req *http.Request) {
addSecurityHeaders(res)
u, err := url.ParseRequestURI(req.RequestURI)
if err != nil {
log.WithError(err).Error("Cannot parse request URI")
return
}
p := u.Path
if p == "/" {
p = "/index.html"
}
p = path.Join(prefix, p)
if d, ok := _bindata[p]; ok {
m := mime.TypeByExtension(path.Ext(p))
res.Header().Add("Content-Type", m)
res.WriteHeader(200)
asset, err := d()
if err != nil {
log.WithError(err).Error("Failed to unwrap asset data for http response")
}
if _, err := res.Write(asset.bytes); err != nil {
log.WithError(err).Error("Failed to write http response")
}
} else if d, ok := _bindata[path.Join(prefix, "index.html")]; ok {
// Angular routing expects that routes are rewritten to serve index.html. For example, if
// requesting /login, this should serve the single page app index.html.
m := mime.TypeByExtension(".html")
res.Header().Add("Content-Type", m)
res.WriteHeader(200)
asset, err := d()
if err != nil {
log.WithError(err).Error("Failed to unwrap asset data for http response")
}
if _, err := res.Write(asset.bytes); err != nil {
log.WithError(err).Error("Failed to write http response")
}
} else { // If index.html is not present, serve 404. This should never happen.
log.WithField("URI", req.RequestURI).Error("Path not found")
res.WriteHeader(404)
if _, err := res.Write([]byte("Not found")); err != nil {
log.WithError(err).Error("Failed to write http response")
}
}
}