homepage/webserver/router/reverse_proxy.go

35 lines
639 B
Go
Raw Normal View History

2022-12-26 01:20:43 +00:00
package router
import (
"net/http"
"net/http/httputil"
"net/url"
"github.com/gin-gonic/gin"
)
func reverseProxyHandle(c *gin.Context) {
defer handleError(c)
path := c.Param("any")
2022-12-26 04:36:19 +00:00
remote, err := url.Parse("http://openvscode-server:3000")
2022-12-26 01:20:43 +00:00
if err != nil {
panic(err)
}
proxy := httputil.NewSingleHostReverseProxy(remote)
//Define the director func
//This is a good place to log, for example
proxy.Director = func(req *http.Request) {
req.Header = c.Request.Header
req.Host = remote.Host
req.URL.Scheme = remote.Scheme
req.URL.Host = remote.Host
req.URL.Path = path
}
proxy.ServeHTTP(c.Writer, c.Request)
}