@@ -3,7 +3,6 @@ package routers
33import (
44 "bytes"
55 "encoding/json"
6- "fmt"
76 "io/ioutil"
87 "net/http"
98 "path"
@@ -17,35 +16,45 @@ import (
1716 "code.gitea.io/gitea/modules/setting"
1817)
1918
20- type Message struct {
21- User * models.User
22- Csrf string
23- Route string
19+ type KitspaceSession struct {
20+ User * models.User
21+ Csrf string
2422}
2523
26- func Kitspace (ctx * context.Context , sess session.Store , x csrf.CSRF ) []byte {
27- m := Message {
24+ func Kitspace (ctx * context.Context , sess session.Store , x csrf.CSRF ) (int , []byte ) {
25+ url := ctx .Req .URL
26+ url .Scheme = "http"
27+ url .Host = "127.0.0.1:3001"
28+ url .Path = strings .Replace (
29+ ctx .Link ,
30+ path .Join (setting .AppSubURL , "/kitspace" ),
31+ "" ,
32+ 1 ,
33+ )
34+
35+ m := KitspaceSession {
2836 User : ctx .User ,
2937 Csrf : x .GetToken (),
30- Route : strings .Replace (
31- ctx .Link ,
32- path .Join (setting .AppSubURL , "/kitspace" ), "" , 1 ,
33- ),
3438 }
39+
3540 b , err := json .Marshal (m )
3641 if err != nil {
3742 panic (err )
3843 }
39- fmt .Println (string (b ))
40- url := "http://localhost:3001/"
41- resp , err := http .Post (url , "application/json" , bytes .NewBuffer (b ))
44+
45+ req , err := http .NewRequest ("GET" , url .String (), bytes .NewBuffer (b ))
46+ req .Header .Add ("Content-Type" , "application/json" )
47+
48+ resp , err := http .DefaultClient .Do (req )
4249 if err != nil {
4350 panic (err )
4451 }
52+
4553 defer resp .Body .Close ()
4654 body , err := ioutil .ReadAll (resp .Body )
4755 if err != nil {
4856 panic (err )
4957 }
50- return body
58+
59+ return resp .StatusCode , body
5160}
0 commit comments