mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01: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"
|
||||
|
||||
//go:embed index.html
|
||||
//go:embed index.gohtml
|
||||
var FS embed.FS
|
||||
|
@ -21,12 +21,15 @@
|
||||
}
|
||||
table {
|
||||
table-layout: fixed;
|
||||
width: 100%;
|
||||
}
|
||||
td {
|
||||
td:last-child {
|
||||
width: 80%;
|
||||
overflow: clip;
|
||||
}
|
||||
td:first-child {
|
||||
width: 20%;
|
||||
overflow: auto;
|
||||
}
|
||||
#banner {
|
||||
background-color: #3b2693;
|
||||
|
@ -37,7 +37,7 @@ func newTestEndpointCommand() *testEndpointCommand {
|
||||
}
|
||||
command := &testEndpointCommand{cmd: cmd}
|
||||
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)
|
||||
}
|
||||
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) {
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
log.Error(err)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ func StaticBuilder(handler http.Handler) http.Handler {
|
||||
logrus.Debugf("directing '%v' to static handler", r.URL.Path)
|
||||
|
||||
staticPath := "build"
|
||||
indexPath := "index.html"
|
||||
indexPath := "index.gohtml"
|
||||
|
||||
// get the absolute path to prevent directory traversal
|
||||
path, err := filepath.Abs(r.URL.Path)
|
||||
@ -35,7 +35,7 @@ func StaticBuilder(handler http.Handler) http.Handler {
|
||||
|
||||
_, err = FS.Open(path)
|
||||
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))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
Loading…
Reference in New Issue
Block a user