Skip to content

Commit 2d26aa8

Browse files
committed
Make kitspace route pass on relevant json
1 parent 884ec66 commit 2d26aa8

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

cmd/web.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ func runWeb(ctx *cli.Context) error {
122122

123123
routes.RegisterKitspaceRoutes(m)
124124

125-
m.Group("/_gitea", func() {
126-
routes.RegisterRoutes(m)
127-
})
125+
routes.RegisterRoutes(m)
128126

129127
// Flag for port number in case first time run conflict.
130128
if ctx.IsSet("port") {

routers/kitspace.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,39 @@ package routers
22

33
import (
44
"bytes"
5+
"code.gitea.io/gitea/models"
56
"code.gitea.io/gitea/modules/context"
7+
"encoding/json"
8+
"fmt"
9+
"github.com/go-macaron/csrf"
10+
"github.com/go-macaron/session"
611
"io/ioutil"
712
"net/http"
13+
"strings"
14+
15+
"gitea.com/macaron/csrf"
16+
"gitea.com/macaron/session"
17+
18+
"code.gitea.io/gitea/models"
19+
"code.gitea.io/gitea/modules/context"
20+
"code.gitea.io/gitea/modules/setting"
821
)
922

10-
func Kitspace(ctx *context.Context) []byte {
23+
type Message struct {
24+
User *models.User
25+
Csrf string
26+
Route string
27+
}
28+
29+
func Kitspace(ctx *context.Context, sess session.Store, x csrf.CSRF) []byte {
30+
m := Message{User: ctx.User, Csrf: x.GetToken(), Route: strings.Replace(ctx.Link, "/kitspace", "", 1)}
31+
fmt.Printf("%+v\n", ctx)
32+
b, err := json.Marshal(m)
33+
if err != nil {
34+
panic(err)
35+
}
1136
url := "http://localhost:3001/"
12-
data := []byte(`{"hello": "world"}`)
13-
resp, err := http.Post(url, "application/json", bytes.NewBuffer(data))
37+
resp, err := http.Post(url, "application/json", bytes.NewBuffer(b))
1438
if err != nil {
1539
panic(err)
1640
}

routers/routes/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func NewMacaron() *macaron.Macaron {
240240
}
241241

242242
func RegisterKitspaceRoutes(m *macaron.Macaron) {
243-
m.Get("/", routers.Kitspace)
243+
m.Get("/kitspace/?*", routers.Kitspace)
244244
}
245245

246246
// RegisterRoutes routes routes to Macaron

0 commit comments

Comments
 (0)