You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2020/09/24 02:14:48 UTC
[apisix-dashboard] branch master updated: fix: regexp for apisix
url in get debuginfo api (#506)
This is an automated email from the ASF dual-hosted git repository.
juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 69199d2 fix: regexp for apisix url in get debuginfo api (#506)
69199d2 is described below
commit 69199d22dd30e47a71c191060a0402d43633addf
Author: liuxiran <be...@126.com>
AuthorDate: Thu Sep 24 10:14:38 2020 +0800
fix: regexp for apisix url in get debuginfo api (#506)
* fix: fix regexp for apisix url in get debuginfo api
* fix: add test case for getRouteWithApisixUrl
---
api/route/route.go | 13 ++++++-------
api/route/route_test.go | 29 +++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/api/route/route.go b/api/route/route.go
index e964272..d5546f4 100644
--- a/api/route/route.go
+++ b/api/route/route.go
@@ -523,16 +523,15 @@ func getRouteWithApisixUrl(c *gin.Context) {
}
result.Name = route.Name
url := conf.BaseUrl
- reg, _ := regexp.Compile("(\\d+\\.\\d+\\.\\d+\\.\\d+)")
- reg2, _ := regexp.Compile("\\:(\\d+)")
+ reg, _ := regexp.Compile("://([^/:]+)(:\\d*)?")
res := reg.FindSubmatch([]byte(url))
- res2 := reg2.FindSubmatch([]byte(url))
- var port string
- if len(res2) > 0 {
- port = string(res2[0])
+ var addr string
+ if len(res) > 0 {
+ addr = string(res[0])
+ addr = strings.Replace(addr, "://", "", 1)
}
routeResponse := &service.RouteResponseWithUrl{}
- routeResponse.Url = string(res[0]) + port
+ routeResponse.Url = addr
routeResponse.RouteRequest = *result
resp, _ := json.Marshal(routeResponse)
c.Data(http.StatusOK, service.ContentType, resp)
diff --git a/api/route/route_test.go b/api/route/route_test.go
index b492623..7c8e5ce 100644
--- a/api/route/route_test.go
+++ b/api/route/route_test.go
@@ -190,6 +190,35 @@ func TestOfflineRoute(t *testing.T) {
handler.Put(uriPrefix + "/routes/" + routePublished.ID.String() + "/offline").Expect(t).Status(http.StatusOK).End()
}
+func TestGetRouteWithApisixUrl(t *testing.T) {
+ // create route
+ handler.Post(uriPrefix+"/routes").
+ Header("Authorization", token).
+ JSON(`{
+ "name":"api-test-get-url",
+ "desc":"",
+ "priority":0,
+ "protocols":["http"],
+ "hosts":["test.com"],
+ "paths":["/*"],
+ "methods":["GET","HEAD","POST","PUT","DELETE","OPTIONS","PATCH"],
+ "status":true,
+ "upstream_protocol":"keep",
+ "plugins":{},
+ "uris":["/*"],
+ "vars":[],
+ "upstream":{"type":"roundrobin","nodes":{"127.0.0.1:443":1},
+ "timeout":{"connect":6000,"send":6000,"read":6000}},
+ "upstream_header":{}
+}`).Expect(t).
+ Status(http.StatusOK).
+ End()
+ //get route
+ route, _ := getRouteByName("api-test-get-url")
+ // get route with apisix url
+ handler.Get(uriPrefix + "/routes/" + route.ID.String() + "/debuginfo").Expect(t).Status(http.StatusOK).End()
+}
+
func getRouteByName(name string) (*service.Route, error) {
db := conf.DB()
route := &service.Route{}