repos / pico

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

commit
facce22
parent
6530b86
author
Eric Bower
date
2025-01-09 13:15:00 -0500 EST
fix(pgs): handle empty filepaths in calc_route
2 files changed,  +40, -1
M pgs/calc_route.go
+4, -1
 1@@ -186,8 +186,11 @@ 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+	}
 8 	// add route as-is without expansion
 9-	if fp != "" && !strings.HasSuffix(fp, "/") {
10+	if !strings.HasSuffix(fp, "/") {
11 		defRoute := shared.GetAssetFileName(&utils.FileEntry{
12 			Filepath: filepath.Join(projectName, fp),
13 		})
M pgs/calc_route_test.go
+36, -0
 1@@ -212,6 +212,42 @@ func TestCalcRoutes(t *testing.T) {
 2 				{Filepath: "test/404.html", Status: 404},
 3 			},
 4 		},
 5+		{
 6+			Name: "redirect-root-full-url",
 7+			Actual: calcRoutes(
 8+				"test",
 9+				"/",
10+				[]*RedirectRule{
11+					{
12+						From:   "/*",
13+						To:     "https://pico.sh",
14+						Status: 301,
15+					},
16+				},
17+			),
18+			Expected: []*HttpReply{
19+				{Filepath: "test/index.html", Status: 200},
20+				{Filepath: "https://pico.sh", Status: 301},
21+			},
22+		},
23+		{
24+			Name: "redirect-empty-route-full-url",
25+			Actual: calcRoutes(
26+				"test",
27+				"",
28+				[]*RedirectRule{
29+					{
30+						From:   "/*",
31+						To:     "https://pico.sh",
32+						Status: 301,
33+					},
34+				},
35+			),
36+			Expected: []*HttpReply{
37+				{Filepath: "test/index.html", Status: 200},
38+				{Filepath: "https://pico.sh", Status: 301},
39+			},
40+		},
41 		{
42 			Name: "redirect-full-url-directory",
43 			Actual: calcRoutes(