This commit is contained in:
loveuer
2024-01-10 20:26:19 +08:00
commit b0435ccc35
14 changed files with 1382 additions and 0 deletions

39
xtest/main.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"github.com/gin-gonic/gin"
"log"
"net/http/httputil"
"net/url"
)
func main() {
app := gin.Default()
app.Any("/*any", func() gin.HandlerFunc {
link := "http://dev.pro.bifrost.com"
host := "dev.pro.bifrost.com"
url, oe := url.Parse(link)
if oe != nil {
log.Fatal("url parse err:", oe)
}
//ps := httputil.NewSingleHostReverseProxy(url)
//ps.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
ps := httputil.ReverseProxy{
Rewrite: func(r *httputil.ProxyRequest) {
r.SetURL(url)
r.Out.Header.Set("Host", host)
r.In.Header.Set("Host", host)
},
}
return func(c *gin.Context) {
c.Request.Header.Set("Host", host)
ps.ServeHTTP(c.Writer, c.Request)
}
}())
log.Fatal(app.Run(":9091"))
}