serve frontend from go
This commit is contained in:
25
pkg/middlewares/stripprefix.go
Normal file
25
pkg/middlewares/stripprefix.go
Normal file
@ -0,0 +1,25 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func AddPrefix(prefix string, h http.Handler) http.Handler {
|
||||
if prefix == "" {
|
||||
return h
|
||||
}
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
p := prefix + r.URL.Path
|
||||
rp := prefix + r.URL.RawPath
|
||||
|
||||
r2 := new(http.Request)
|
||||
*r2 = *r
|
||||
r2.URL = new(url.URL)
|
||||
*r2.URL = *r.URL
|
||||
r2.URL.Path = p
|
||||
r2.URL.RawPath = rp
|
||||
h.ServeHTTP(w, r2)
|
||||
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user