web

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package web is the service to serve the Prysm web UI. See https://github.com/prysmaticlabs/prysm-web-ui

Index

Constants

This section is empty.

Variables

View Source
var Handler = func(res http.ResponseWriter, req *http.Request) {
	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 := site[p]; ok {
		m := mime.TypeByExtension(path.Ext(p))
		res.Header().Add("Content-Type", m)
		res.WriteHeader(200)
		if _, err := res.Write(d); err != nil {
			log.WithError(err).Error("Failed to write http response")
		}
	} else if d, ok := site[path.Join(prefix, "index.html")]; ok {

		m := mime.TypeByExtension(".html")
		res.Header().Add("Content-Type", m)
		res.WriteHeader(200)
		if _, err := res.Write(d); err != nil {
			log.WithError(err).Error("Failed to write http response")
		}
	} else {
		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")
		}
	}
}

Handler serves web requests from the bundled site data.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL