mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge branch 'fix-root-route-invocation' into 'master'
Allow calling root route on app Closes #64 See merge request !91
This commit is contained in:
@@ -94,9 +94,14 @@ func (s *Server) handleRequest(c *gin.Context, enqueue models.Enqueue) {
|
|||||||
payload = strings.NewReader(reqPayload)
|
payload = strings.NewReader(reqPayload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r, routeExists := c.Get(api.Path)
|
||||||
|
if !routeExists {
|
||||||
|
r = "/"
|
||||||
|
}
|
||||||
|
|
||||||
reqRoute := &models.Route{
|
reqRoute := &models.Route{
|
||||||
AppName: c.MustGet(api.AppName).(string),
|
AppName: c.MustGet(api.AppName).(string),
|
||||||
Path: path.Clean(c.MustGet(api.Path).(string)),
|
Path: path.Clean(r.(string)),
|
||||||
}
|
}
|
||||||
|
|
||||||
s.FireBeforeDispatch(ctx, reqRoute)
|
s.FireBeforeDispatch(ctx, reqRoute)
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ func TestRouteRunnerExecution(t *testing.T) {
|
|||||||
{Name: "myapp", Config: models.Config{}},
|
{Name: "myapp", Config: models.Config{}},
|
||||||
},
|
},
|
||||||
[]*models.Route{
|
[]*models.Route{
|
||||||
|
{Path: "/", AppName: "myapp", Image: "funcy/hello", Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||||
{Path: "/myroute", AppName: "myapp", Image: "funcy/hello", Headers: map[string][]string{"X-Function": {"Test"}}},
|
{Path: "/myroute", AppName: "myapp", Image: "funcy/hello", Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||||
{Path: "/myerror", AppName: "myapp", Image: "funcy/error", Headers: map[string][]string{"X-Function": {"Test"}}},
|
{Path: "/myerror", AppName: "myapp", Image: "funcy/error", Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||||
}, nil, nil,
|
}, nil, nil,
|
||||||
@@ -139,10 +140,12 @@ func TestRouteRunnerExecution(t *testing.T) {
|
|||||||
expectedCode int
|
expectedCode int
|
||||||
expectedHeaders map[string][]string
|
expectedHeaders map[string][]string
|
||||||
}{
|
}{
|
||||||
|
{"/r/myapp/", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
||||||
{"/r/myapp/myroute", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
{"/r/myapp/myroute", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
||||||
{"/r/myapp/myerror", ``, "GET", http.StatusInternalServerError, map[string][]string{"X-Function": {"Test"}}},
|
{"/r/myapp/myerror", ``, "GET", http.StatusInternalServerError, map[string][]string{"X-Function": {"Test"}}},
|
||||||
|
|
||||||
// Added same tests again to check if time is reduced by the auth cache
|
// Added same tests again to check if time is reduced by the auth cache
|
||||||
|
{"/r/myapp/", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
||||||
{"/r/myapp/myroute", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
{"/r/myapp/myroute", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
||||||
{"/r/myapp/myerror", ``, "GET", http.StatusInternalServerError, map[string][]string{"X-Function": {"Test"}}},
|
{"/r/myapp/myerror", ``, "GET", http.StatusInternalServerError, map[string][]string{"X-Function": {"Test"}}},
|
||||||
} {
|
} {
|
||||||
|
|||||||
@@ -328,6 +328,7 @@ func (s *Server) bindHandlers(ctx context.Context) {
|
|||||||
|
|
||||||
engine.DELETE("/tasks", s.handleTaskRequest)
|
engine.DELETE("/tasks", s.handleTaskRequest)
|
||||||
engine.GET("/tasks", s.handleTaskRequest)
|
engine.GET("/tasks", s.handleTaskRequest)
|
||||||
|
engine.Any("/r/:app", s.handleRunnerRequest)
|
||||||
engine.Any("/r/:app/*route", s.handleRunnerRequest)
|
engine.Any("/r/:app/*route", s.handleRunnerRequest)
|
||||||
|
|
||||||
// This final route is used for extensions, see Server.Add
|
// This final route is used for extensions, see Server.Add
|
||||||
|
|||||||
Reference in New Issue
Block a user