mirror of
https://github.com/openziti/zrok.git
synced 2025-06-25 04:02:15 +02:00
better test endpoint ui layout (#36)
This commit is contained in:
parent
d8f514efb7
commit
9e26229ff0
@ -2,5 +2,5 @@ package endpoint_ui
|
|||||||
|
|
||||||
import "embed"
|
import "embed"
|
||||||
|
|
||||||
//go:embed index.html
|
//go:embed index.gohtml
|
||||||
var FS embed.FS
|
var FS embed.FS
|
||||||
|
@ -21,12 +21,15 @@
|
|||||||
}
|
}
|
||||||
table {
|
table {
|
||||||
table-layout: fixed;
|
table-layout: fixed;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
td {
|
td:last-child {
|
||||||
width: 80%;
|
width: 80%;
|
||||||
|
overflow: clip;
|
||||||
}
|
}
|
||||||
td:first-child {
|
td:first-child {
|
||||||
width: 20%;
|
width: 20%;
|
||||||
|
overflow: auto;
|
||||||
}
|
}
|
||||||
#banner {
|
#banner {
|
||||||
background-color: #3b2693;
|
background-color: #3b2693;
|
||||||
|
@ -37,7 +37,7 @@ func newTestEndpointCommand() *testEndpointCommand {
|
|||||||
}
|
}
|
||||||
command := &testEndpointCommand{cmd: cmd}
|
command := &testEndpointCommand{cmd: cmd}
|
||||||
var err error
|
var err error
|
||||||
if command.t, err = template.ParseFS(endpoint_ui.FS, "index.html"); err != nil {
|
if command.t, err = template.ParseFS(endpoint_ui.FS, "index.gohtml"); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cmd.Flags().StringVarP(&command.address, "address", "a", "0.0.0.0", "The address for the HTTP listener")
|
cmd.Flags().StringVarP(&command.address, "address", "a", "0.0.0.0", "The address for the HTTP listener")
|
||||||
@ -48,14 +48,13 @@ func newTestEndpointCommand() *testEndpointCommand {
|
|||||||
|
|
||||||
func (cmd *testEndpointCommand) run(_ *cobra.Command, _ []string) {
|
func (cmd *testEndpointCommand) run(_ *cobra.Command, _ []string) {
|
||||||
http.HandleFunc("/", cmd.serveIndex)
|
http.HandleFunc("/", cmd.serveIndex)
|
||||||
http.HandleFunc("/index.html", cmd.serveIndex)
|
|
||||||
if err := http.ListenAndServe(fmt.Sprintf("%v:%d", cmd.address, cmd.port), nil); err != nil {
|
if err := http.ListenAndServe(fmt.Sprintf("%v:%d", cmd.address, cmd.port), nil); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *testEndpointCommand) serveIndex(w http.ResponseWriter, r *http.Request) {
|
func (cmd *testEndpointCommand) serveIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
logrus.Infof("%v {%v} -> /index.html", r.RemoteAddr, r.Host)
|
logrus.Infof("%v {%v} -> /index.gohtml", r.RemoteAddr, r.Host)
|
||||||
if err := cmd.t.Execute(w, newEndpointData(r)); err != nil {
|
if err := cmd.t.Execute(w, newEndpointData(r)); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func StaticBuilder(handler http.Handler) http.Handler {
|
|||||||
logrus.Debugf("directing '%v' to static handler", r.URL.Path)
|
logrus.Debugf("directing '%v' to static handler", r.URL.Path)
|
||||||
|
|
||||||
staticPath := "build"
|
staticPath := "build"
|
||||||
indexPath := "index.html"
|
indexPath := "index.gohtml"
|
||||||
|
|
||||||
// get the absolute path to prevent directory traversal
|
// get the absolute path to prevent directory traversal
|
||||||
path, err := filepath.Abs(r.URL.Path)
|
path, err := filepath.Abs(r.URL.Path)
|
||||||
@ -35,7 +35,7 @@ func StaticBuilder(handler http.Handler) http.Handler {
|
|||||||
|
|
||||||
_, err = FS.Open(path)
|
_, err = FS.Open(path)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// file does not exist, serve index.html
|
// file does not exist, serve index.gohtml
|
||||||
index, err := FS.ReadFile(filepath.Join(staticPath, indexPath))
|
index, err := FS.ReadFile(filepath.Join(staticPath, indexPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user