homepage/webserver/router/reverse_proxy.go
2022-12-26 04:36:19 +00:00

35 lines
639 B
Go

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")
remote, err := url.Parse("http://openvscode-server:3000")
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)
}