- commit
- 4aa64c9
- parent
- 19e655a
- author
- Eric Bower
- date
- 2025-06-05 20:00:21 -0400 EDT
fix(pgs): redirect to file
3 files changed,
+25,
-1
+5,
-1
1@@ -174,9 +174,13 @@ func genRedirectRoute(actual string, fromStr string, to string) string {
2 }
3
4 fin := []string{"/"}
5+ addSuffix := false
6
7 for _, item := range toList {
8 if strings.HasSuffix(item, ":splat") {
9+ if strings.HasSuffix(actual, "/") {
10+ addSuffix = true
11+ }
12 fin = append(fin, mapper[item])
13 } else if mapper[item] != "" {
14 fin = append(fin, mapper[item])
15@@ -186,7 +190,7 @@ func genRedirectRoute(actual string, fromStr string, to string) string {
16 }
17
18 result := prefix + filepath.Join(fin...)
19- if !strings.HasSuffix(result, "/") && (strings.HasSuffix(to, "/") || strings.HasSuffix(actual, "/")) {
20+ if !strings.HasSuffix(result, "/") && (strings.HasSuffix(to, "/") || addSuffix) {
21 result += "/"
22 }
23 return result
+19,
-0
1@@ -644,6 +644,25 @@ func TestCalcRoutes(t *testing.T) {
2 {Filepath: "public/404.html", Status: 404},
3 },
4 },
5+ {
6+ Name: "redirect-to-file",
7+ Actual: calcRoutes(
8+ "public",
9+ "/feeds/rss/",
10+ []*RedirectRule{
11+ {
12+ From: "/feeds/rss/",
13+ To: "/index.xml",
14+ Status: 301,
15+ },
16+ },
17+ ),
18+ Expected: []*HttpReply{
19+ {Filepath: "public/feeds/rss/index.html", Status: 200},
20+ {Filepath: "/index.xml", Status: 301},
21+ {Filepath: "public/404.html", Status: 404},
22+ },
23+ },
24 }
25
26 for _, fixture := range fixtures {
+1,
-0
1@@ -92,6 +92,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2 status := http.StatusOK
3 attempts := []string{}
4 for _, fp := range routes {
5+ logger.Info("attemptming to serve route", "route", fp.Filepath, "status", fp.Status, "query", fp.Query)
6 destUrl, err := url.Parse(fp.Filepath)
7 if err != nil {
8 http.Error(w, err.Error(), http.StatusInternalServerError)