repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
3eda1b9
parent
a942011
author
Eric Bower
date
2025-01-10 09:33:12 -0500 EST
fix(pgs): add forward slash to prefix of filepath for calc_route
2 files changed,  +22, -2
M pgs/calc_route.go
+2, -2
 1@@ -194,8 +194,8 @@ func genRedirectRoute(actual string, fromStr string, to string) string {
 2 
 3 func calcRoutes(projectName, fp string, userRedirects []*RedirectRule) []*HttpReply {
 4 	rts := []*HttpReply{}
 5-	if fp == "" {
 6-		fp = "/"
 7+	if !strings.HasPrefix(fp, "/") {
 8+		fp = "/" + fp
 9 	}
10 	// add route as-is without expansion
11 	if !strings.HasSuffix(fp, "/") {
M pgs/calc_route_test.go
+20, -0
 1@@ -624,6 +624,26 @@ func TestCalcRoutes(t *testing.T) {
 2 				{Filepath: "public/404.html", Status: 404},
 3 			},
 4 		},
 5+		{
 6+			Name: "implicit-prefix-slash-redirect",
 7+			Actual: calcRoutes(
 8+				"public",
 9+				"software/scripts",
10+				[]*RedirectRule{
11+					{
12+						From:   "/software/concat/*",
13+						To:     "/software/scripts/:splat",
14+						Status: 301,
15+					},
16+				},
17+			),
18+			Expected: []*HttpReply{
19+				{Filepath: "public/software/scripts", Status: 200},
20+				{Filepath: "public/software/scripts.html", Status: 200},
21+				{Filepath: "/software/scripts/", Status: 301},
22+				{Filepath: "public/404.html", Status: 404},
23+			},
24+		},
25 	}
26 
27 	for _, fixture := range fixtures {