Preparation for alternative context path.
The contextpath parameter in converge.go is temporary and should be removed later. What is needed is autodetectio of the context path for the usage page and passing on the context for rendering.
This commit is contained in:
parent
2df296d3c3
commit
9456665a6f
@ -286,10 +286,6 @@ func main() {
|
||||
if err != nil {
|
||||
printHelp(fmt.Sprintf("Invalid URL %s", wsURL))
|
||||
}
|
||||
if url.Path != "" && url.Path != "/" {
|
||||
printHelp(fmt.Sprintf("Only a base URL without path may be specified: %s", wsURL))
|
||||
}
|
||||
|
||||
wsURL += "/agent/" + id
|
||||
|
||||
dialer := websocket.Dialer{
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
func parsePublicId(path string) (publicId string, _ error) {
|
||||
pattern := regexp.MustCompile("^/[^/]+/([^/]+)$")
|
||||
pattern := regexp.MustCompile("/([^/]+)$")
|
||||
matches := pattern.FindStringSubmatch(path)
|
||||
if len(matches) != 2 {
|
||||
return "", fmt.Errorf("Invalid URL path '%s'", path)
|
||||
@ -159,20 +159,31 @@ func main() {
|
||||
}
|
||||
|
||||
// websocket endpoints
|
||||
http.HandleFunc("/agent/", registrationService.Handle)
|
||||
http.HandleFunc("/client/", clientService.Handle)
|
||||
http.HandleFunc("/ws/sessions", sessionService.Handle)
|
||||
|
||||
// TODO remove, simulate contextpath
|
||||
|
||||
contextpath := ""
|
||||
http.HandleFunc(contextpath+"/agent/", registrationService.Handle)
|
||||
http.HandleFunc(contextpath+"/client/", clientService.Handle)
|
||||
http.HandleFunc(contextpath+"/ws/sessions", sessionService.Handle)
|
||||
|
||||
// create filehandler with templating for html files.
|
||||
http.Handle("/docs/", http.StripPrefix("/docs/", http.HandlerFunc(pageHandler)))
|
||||
http.Handle("/static/", http.StripPrefix("/static/",
|
||||
http.Handle(contextpath+"/docs/", http.StripPrefix(contextpath+"/docs/", http.HandlerFunc(pageHandler)))
|
||||
http.Handle(contextpath+"/static/", http.StripPrefix(contextpath+"/static/",
|
||||
http.FileServer(http.Dir(staticdir))))
|
||||
http.Handle("/downloads/", http.StripPrefix("/downloads/",
|
||||
http.Handle(contextpath+"/downloads/", http.StripPrefix(contextpath+"/downloads/",
|
||||
http.FileServer(http.Dir(downloaddir))))
|
||||
http.HandleFunc("/", catchAllHandler)
|
||||
|
||||
// TODO remove for testing contextpath
|
||||
|
||||
catchAllHandler2 := func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, contextpath+"/docs", http.StatusFound)
|
||||
return
|
||||
}
|
||||
http.HandleFunc(contextpath+"/", catchAllHandler2)
|
||||
|
||||
// create usage generator
|
||||
http.HandleFunc("/usage", generateCLIExammple)
|
||||
http.HandleFunc(contextpath+"/usage", generateCLIExammple)
|
||||
|
||||
// Start HTTP server
|
||||
fmt.Println("Rendez-vous server listening on :8000")
|
||||
|
@ -35,6 +35,8 @@ templ BasePage(tab int) {
|
||||
console.log("timezone override for websockets")
|
||||
window.originalWebSocket = htmx.createWebSocket
|
||||
htmx.createWebSocket = function(url) {
|
||||
url = new URL(url, window.location.href).href
|
||||
url = url.replace(/^http/, 'ws');
|
||||
let modifiedUrl = url + "?timezone=" + getTimezone()
|
||||
return window.originalWebSocket(modifiedUrl)
|
||||
}
|
||||
@ -43,7 +45,7 @@ templ BasePage(tab int) {
|
||||
document.body.addEventListener(
|
||||
"htmx:configRequest",
|
||||
function(evt) {
|
||||
console.log("Adding timezone to htmx request headers");
|
||||
console.log("Adding timezone to htmx request headers and making URL absolute");
|
||||
evt.detail.headers["X-Timezone"] = getTimezone();
|
||||
}
|
||||
);
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
|
||||
templ Sessions(state *models.State, loc *time.Location) {
|
||||
<div hx-ext="ws" ws-connect="/ws/sessions">
|
||||
<div hx-ext="ws" ws-connect="../ws/sessions">
|
||||
<h1>sessions</h1>
|
||||
|
||||
<div id="status">
|
||||
|
@ -146,7 +146,7 @@ templ Usage(access models.ConvergeAccess) {
|
||||
</style>
|
||||
|
||||
<form id="inputs" novalidate
|
||||
hx-post="/usage"
|
||||
hx-post="../usage"
|
||||
method="post"
|
||||
hx-trigger="load,input delay:500ms,change,formdataloaded"
|
||||
hx-target="#example-cli"
|
||||
|
Loading…
Reference in New Issue
Block a user