You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/08/09 01:32:28 UTC
[incubator-devlake] branch main updated: refactor: improve the bodyTamper.Write method for swagger/doc.json (#5835)
This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new eae2bdedd refactor: improve the bodyTamper.Write method for swagger/doc.json (#5835)
eae2bdedd is described below
commit eae2bdeddb686e979e97ceb1ee1d66d041972f4f
Author: Liang Zhang <li...@merico.dev>
AuthorDate: Wed Aug 9 09:32:23 2023 +0800
refactor: improve the bodyTamper.Write method for swagger/doc.json (#5835)
---
backend/server/api/api.go | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/backend/server/api/api.go b/backend/server/api/api.go
index 8cbe7d006..2faa423b6 100644
--- a/backend/server/api/api.go
+++ b/backend/server/api/api.go
@@ -18,7 +18,7 @@ limitations under the License.
package api
import (
- "bytes"
+ "encoding/json"
"fmt"
"net/http"
"net/url"
@@ -190,8 +190,18 @@ type bodyTamper struct {
gin.ResponseWriter
}
+// Write intercepts the response body and modifies the base path
func (w bodyTamper) Write(b []byte) (int, error) {
- b = bytes.Replace(b, []byte(`"basePath": ""`), []byte(`"basePath": "/api"`), 1)
+ var m map[string]interface{}
+ err := json.Unmarshal(b, &m)
+ if err != nil {
+ return 0, err
+ }
+ m["basePath"] = "/api"
+ b, err = json.Marshal(m)
+ if err != nil {
+ return 0, err
+ }
return w.ResponseWriter.Write(b)
}