diff --git a/dashboard/yarn.lock b/dashboard/yarn.lock index 2f215b6..8503e6a 100644 --- a/dashboard/yarn.lock +++ b/dashboard/yarn.lock @@ -2221,7 +2221,7 @@ postcss@^5.2.17: source-map "^0.5.6" supports-color "^3.2.3" -postcss@^8.1.10, postcss@^8.4.12: +postcss@^8.1.10: version "8.4.12" resolved "https://registry.npmmirror.com/postcss/-/postcss-8.4.12.tgz" integrity sha512-lg6eITwYe9v6Hr5CncVbK70SoioNQIq81nsaG86ev5hAidQvmOeETBqs7jm43K2F5/Ley3ytDtriImV6TpNiSg== @@ -2230,6 +2230,15 @@ postcss@^8.1.10, postcss@^8.4.12: picocolors "^1.0.0" source-map-js "^1.0.2" +postcss@^8.4.12: + version "8.4.12" + resolved "https://registry.npmmirror.com/postcss/-/postcss-8.4.12.tgz#1e7de78733b28970fa4743f7da6f3763648b1905" + integrity sha512-lg6eITwYe9v6Hr5CncVbK70SoioNQIq81nsaG86ev5hAidQvmOeETBqs7jm43K2F5/Ley3ytDtriImV6TpNiSg== + dependencies: + nanoid "^3.3.1" + picocolors "^1.0.0" + source-map-js "^1.0.2" + posthtml-parser@^0.2.0, posthtml-parser@^0.2.1: version "0.2.1" resolved "https://registry.npmmirror.com/posthtml-parser/-/posthtml-parser-0.2.1.tgz#35d530de386740c2ba24ff2eb2faf39ccdf271dd" diff --git a/main.go b/main.go index 32e548e..d175818 100644 --- a/main.go +++ b/main.go @@ -7,8 +7,16 @@ package main import ( + "fmt" + "log" + "net/http" + "net/http/httputil" + "net/url" + + "github.com/dtm-labs/dtm/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr/entry" _ "github.com/dtm-labs/dtm/dtmsvr/microservices" + "github.com/gin-gonic/gin" ) // Version defines version info. It is set by -ldflags. @@ -17,6 +25,32 @@ var Version string func main() { app := entry.Main(&Version) if app != nil { + addDashboard(app) select {} } } +func addDashboard(app *gin.Engine) { + app.GET("/dashboard/*name", proxyDashboard) + app.GET("/@vite/*name", proxyDashboard) + app.GET("/node_modules/*name", proxyDashboard) + app.GET("/src/*name", proxyDashboard) + app.GET("/@id/*name", proxyDashboard) +} + +func proxyDashboard(c *gin.Context) { + + target := "127.0.0.1:5000" + u := &url.URL{} + u.Scheme = "http" + u.Host = target + proxy := httputil.NewSingleHostReverseProxy(u) + + proxy.ErrorHandler = func(rw http.ResponseWriter, req *http.Request, err error) { + log.Printf("http: proxy error: %v", err) + ret := fmt.Sprintf("http proxy error %v", err) + _, _ = rw.Write([]byte(ret)) + } + logger.Debugf("proxy dashboard to %s", target) + proxy.ServeHTTP(c.Writer, c.Request) + +}