mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 15:22:47 +01:00
41 lines
866 B
Go
Executable File
41 lines
866 B
Go
Executable File
package api
|
|
|
|
import (
|
|
"io/fs"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
func VueStatic(fsys fs.FS) func(w http.ResponseWriter, r *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
handler := http.FileServer(http.FS(fsys))
|
|
|
|
if strings.HasPrefix(r.URL.Path, "/static/") {
|
|
handler = http.StripPrefix("/static/", handler)
|
|
} else {
|
|
r.URL.Path = "/"
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
}
|
|
|
|
func Static(fsys fs.FS) func(w http.ResponseWriter, r *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
http.FileServer(http.FS(fsys)).ServeHTTP(w, r)
|
|
}
|
|
}
|
|
|
|
func Proxy(dest string) func(w http.ResponseWriter, r *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
u, _ := url.Parse(dest)
|
|
proxy := httputil.NewSingleHostReverseProxy(u)
|
|
|
|
r.Host = r.URL.Host
|
|
|
|
proxy.ServeHTTP(w, r)
|
|
}
|
|
}
|