Skip to content

Commit 6d7ce14

Browse files
committed
feat: add support for custom function routes
1 parent 5babef6 commit 6d7ce14

File tree

6 files changed

+152
-13
lines changed

6 files changed

+152
-13
lines changed

go/models/function_config.go

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/models/function_route.go

+49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/porcelain/deploy.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -793,10 +793,20 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep
793793
})
794794
}
795795

796-
if function.DisplayName != "" || function.Generator != "" {
796+
routes := make([]*models.FunctionRoute, len(function.Routes))
797+
for i, route := range function.Routes {
798+
routes[i] = &models.FunctionRoute{
799+
Pattern: route.Pattern,
800+
Literal: route.Literal,
801+
Expression: route.Expression,
802+
}
803+
}
804+
805+
if function.DisplayName != "" || function.Generator != "" || len(routes) > 0 {
797806
functionsConfig[file.Name] = models.FunctionConfig{
798807
DisplayName: function.DisplayName,
799808
Generator: function.Generator,
809+
Routes: routes,
800810
}
801811
}
802812

go/porcelain/deploy_test.go

+23-3
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,17 @@ func TestBundleWithManifest(t *testing.T) {
472472
"displayName": "Hello Javascript Function",
473473
"generator": "@netlify/[email protected]",
474474
"name": "hello-js-function-test",
475-
"schedule": "* * * * *"
475+
"schedule": "* * * * *",
476+
"routes": [
477+
{
478+
"pattern": "/products",
479+
"literal": "/products"
480+
},
481+
{
482+
"pattern": "/products/:id",
483+
"expression": "^/products/(.*)$"
484+
}
485+
]
476486
},
477487
{
478488
"path": "%s",
@@ -502,9 +512,19 @@ func TestBundleWithManifest(t *testing.T) {
502512
assert.Equal(t, "some-other-runtime", functions.Files["hello-py-function-test"].Runtime)
503513
assert.Equal(t, "stream", functions.Files["hello-py-function-test"].FunctionMetadata.InvocationMode)
504514

515+
helloJSConfig := functionsConfig["hello-js-function-test"]
516+
505517
assert.Equal(t, 1, len(functionsConfig))
506-
assert.Equal(t, "Hello Javascript Function", functionsConfig["hello-js-function-test"].DisplayName)
507-
assert.Equal(t, "@netlify/[email protected]", functionsConfig["hello-js-function-test"].Generator)
518+
assert.Equal(t, "Hello Javascript Function", helloJSConfig.DisplayName)
519+
assert.Equal(t, "@netlify/[email protected]", helloJSConfig.Generator)
520+
521+
assert.Equal(t, "/products", helloJSConfig.Routes[0].Pattern)
522+
assert.Equal(t, "/products", helloJSConfig.Routes[0].Literal)
523+
assert.Empty(t, helloJSConfig.Routes[0].Expression)
524+
525+
assert.Equal(t, "/products/:id", helloJSConfig.Routes[1].Pattern)
526+
assert.Empty(t, helloJSConfig.Routes[1].Literal)
527+
assert.Equal(t, "^/products/(.*)$", helloJSConfig.Routes[1].Expression)
508528
}
509529

510530
func TestReadZipRuntime(t *testing.T) {

go/porcelain/functions_manifest.go

+16-9
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ type functionsManifest struct {
77
}
88

99
type functionsManifestEntry struct {
10-
MainFile string `json:"mainFile"`
11-
Name string `json:"name"`
12-
Path string `json:"path"`
13-
Runtime string `json:"runtime"`
14-
RuntimeVersion string `json:"runtimeVersion"`
15-
Schedule string `json:"schedule"`
16-
DisplayName string `json:"displayName"`
17-
Generator string `json:"generator"`
18-
InvocationMode string `json:"invocationMode"`
10+
MainFile string `json:"mainFile"`
11+
Name string `json:"name"`
12+
Path string `json:"path"`
13+
Runtime string `json:"runtime"`
14+
RuntimeVersion string `json:"runtimeVersion"`
15+
Schedule string `json:"schedule"`
16+
DisplayName string `json:"displayName"`
17+
Generator string `json:"generator"`
18+
InvocationMode string `json:"invocationMode"`
19+
Routes []functionRoute `json:"routes"`
20+
}
21+
22+
type functionRoute struct {
23+
Pattern string `json:"pattern"`
24+
Literal string `json:"literal"`
25+
Expression string `json:"expression"`
1926
}

swagger.yml

+13
Original file line numberDiff line numberDiff line change
@@ -3620,6 +3620,19 @@ definitions:
36203620
type: string
36213621
generator:
36223622
type: string
3623+
routes:
3624+
type: array
3625+
items:
3626+
$ref: '#/definitions/functionRoute'
3627+
functionRoute:
3628+
type: object
3629+
properties:
3630+
pattern:
3631+
type: string
3632+
literal:
3633+
type: string
3634+
expression:
3635+
type: string
36233636
parameters:
36243637
page:
36253638
type: integer

0 commit comments

Comments
 (0)