mirror of
https://github.com/mentos1386/zdravko.git
synced 2025-03-14 13:11:05 +00:00
feat(temporal): expose ui under authentication
This commit is contained in:
parent
e74322f296
commit
b516c979b3
4 changed files with 55 additions and 1 deletions
|
@ -54,6 +54,9 @@ func main() {
|
||||||
r.HandleFunc("/oauth2/callback", h.OAuth2CallbackGET).Methods("GET")
|
r.HandleFunc("/oauth2/callback", h.OAuth2CallbackGET).Methods("GET")
|
||||||
r.HandleFunc("/oauth2/logout", h.Authenticated(h.OAuth2LogoutGET)).Methods("GET")
|
r.HandleFunc("/oauth2/logout", h.Authenticated(h.OAuth2LogoutGET)).Methods("GET")
|
||||||
|
|
||||||
|
// Temporal UI
|
||||||
|
r.PathPrefix("/temporal").HandlerFunc(h.Authenticated(h.Temporal))
|
||||||
|
|
||||||
// 404
|
// 404
|
||||||
r.PathPrefix("/").HandlerFunc(h.Error404).Methods("GET")
|
r.PathPrefix("/").HandlerFunc(h.Error404).Methods("GET")
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ func frontendServer() {
|
||||||
Port: 8223,
|
Port: 8223,
|
||||||
TemporalGRPCAddress: "localhost:7233",
|
TemporalGRPCAddress: "localhost:7233",
|
||||||
EnableUI: true,
|
EnableUI: true,
|
||||||
UIAssetPath: "",
|
PublicPath: "/temporal",
|
||||||
Codec: uiconfig.Codec{
|
Codec: uiconfig.Codec{
|
||||||
Endpoint: "",
|
Endpoint: "",
|
||||||
},
|
},
|
||||||
|
@ -121,6 +121,7 @@ func frontendServer() {
|
||||||
if err := server.Start(); err != nil {
|
if err := server.Start(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
server.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -19,6 +19,7 @@ var SettingsPages = []*components.Page{
|
||||||
{Path: "/settings", Title: "Overview"},
|
{Path: "/settings", Title: "Overview"},
|
||||||
{Path: "/settings/healthchecks", Title: "Healthchecks"},
|
{Path: "/settings/healthchecks", Title: "Healthchecks"},
|
||||||
{Path: "/settings/workers", Title: "Workers"},
|
{Path: "/settings/workers", Title: "Workers"},
|
||||||
|
{Path: "/temporal", Title: "Temporal"},
|
||||||
{Path: "/oauth2/logout", Title: "Logout"},
|
{Path: "/oauth2/logout", Title: "Logout"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
49
internal/handlers/temporal.go
Normal file
49
internal/handlers/temporal.go
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
var customTransport = http.DefaultTransport
|
||||||
|
|
||||||
|
func (h *BaseHandler) Temporal(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
|
||||||
|
// Create a new HTTP request with the same method, URL, and body as the original request
|
||||||
|
targetURL := r.URL
|
||||||
|
targetURL.Host = "localhost:8223"
|
||||||
|
targetURL.Scheme = "http"
|
||||||
|
|
||||||
|
proxyReq, err := http.NewRequest(r.Method, targetURL.String(), r.Body)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Error creating proxy request", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the headers from the original request to the proxy request
|
||||||
|
for name, values := range r.Header {
|
||||||
|
for _, value := range values {
|
||||||
|
proxyReq.Header.Add(name, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the proxy request using the custom transport
|
||||||
|
resp, err := customTransport.RoundTrip(proxyReq)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Error sending proxy request", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Copy the headers from the proxy response to the original response
|
||||||
|
for name, values := range resp.Header {
|
||||||
|
for _, value := range values {
|
||||||
|
w.Header().Add(name, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the status code of the original response to the status code of the proxy response
|
||||||
|
w.WriteHeader(resp.StatusCode)
|
||||||
|
|
||||||
|
// Copy the body of the proxy response to the original response
|
||||||
|
io.Copy(w, resp.Body)
|
||||||
|
}
|
Loading…
Reference in a new issue