The code and data behind xeiaso.net
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

redirect christine.website to xeiaso.net

Signed-off-by: Xe Iaso <me@xeiaso.net>

Xe Iaso c09361b9 40b1165a

+86 -30
+2 -1
cmd/xesite/main.go
··· 26 26 gitBranch = flag.String("git-branch", "main", "Git branch to clone") 27 27 gitRepo = flag.String("git-repo", "https://github.com/Xe/site", "Git repository to clone") 28 28 githubSecret = flag.String("github-secret", "", "GitHub secret to use for webhooks") 29 - internalAPIBind = flag.String("internal-api-bind", ":3001", "Port to listen on for the internal API") 29 + internalAPIBind = flag.String("internal-api-bind", ":3001", "Port to listen on for the internal API") 30 30 miToken = flag.String("mi-token", "", "Token to use for the mi API") 31 31 patreonSaasProxyURL = flag.String("patreon-saasproxy-url", "http://xesite-patreon-saasproxy.flycast", "URL to use for the patreon saasproxy") 32 32 siteURL = flag.String("site-url", "https://xeiaso.net/", "URL to use for the site") ··· 112 112 h = internal.CacheHeader(h) 113 113 h = internal.AcceptEncodingMiddleware(h) 114 114 h = internal.RefererMiddleware(h) 115 + h = internal.DomainRedirect(h, *devel) 115 116 116 117 slog.Info("starting server", "bind", *bind) 117 118 log.Fatal(http.Serve(ln, h))
+1 -29
internal/accept_encoding_test.go
··· 52 52 if lqs[3].Q != 0.7 { 53 53 t.Errorf("lqs[3].Q = %f, want 0.7", lqs[3].Q) 54 54 } 55 - 56 - t.Run("invalid", func(t *testing.T) { 57 - panicked := false 58 - acptEnc := "taco;q=beer" 59 - defer func() { 60 - if r := recover(); r != nil { 61 - panicked = true 62 - } 63 - if !panicked { 64 - t.Errorf("did not panic") 65 - } 66 - }() 67 - ParseAcceptLanguage(acptEnc) 68 - }) 69 55 } 70 56 71 57 func TestParseAcceptEncoding(t *testing.T) { 72 - acptEnc := "gzip, deflate, br;q=0.9" 58 + acptEnc := "gzip, deflate, br;q=1" 73 59 eqs := ParseAcceptEncoding(acptEnc) 74 60 if len(eqs) != 3 { 75 61 t.Errorf("len(eqs) = %d, want 3", len(eqs)) ··· 92 78 if eqs[2].Q != 1 { 93 79 t.Errorf("eqs[2].Q = %f, want 1", eqs[2].Q) 94 80 } 95 - 96 - t.Run("invalid", func(t *testing.T) { 97 - panicked := false 98 - acptEnc := "gzip, deflate, taco;q=beer" 99 - defer func() { 100 - if r := recover(); r != nil { 101 - panicked = true 102 - } 103 - if !panicked { 104 - t.Errorf("did not panic") 105 - } 106 - }() 107 - ParseAcceptEncoding(acptEnc) 108 - }) 109 81 }
+37
internal/domain_redirect.go
··· 1 + package internal 2 + 3 + import ( 4 + "flag" 5 + "fmt" 6 + "net/http" 7 + ) 8 + 9 + var ( 10 + redirectDomain = flag.String("redirect-domain", "xeiaso.net", "Domain to redirect to") 11 + 12 + allowedPaths = map[string]struct{}{ 13 + "/blog.rss": {}, 14 + "/blog.atom": {}, 15 + "/blog.json": {}, 16 + } 17 + ) 18 + 19 + func DomainRedirect(next http.Handler, development bool) http.Handler { 20 + if development { 21 + return next 22 + } 23 + 24 + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 25 + if _, ok := allowedPaths[r.URL.Path]; ok { 26 + next.ServeHTTP(w, r) 27 + return 28 + } 29 + 30 + if r.Host != *redirectDomain { 31 + http.Redirect(w, r, fmt.Sprintf("https://%s%s", *redirectDomain, r.RequestURI), http.StatusMovedPermanently) 32 + return 33 + } 34 + 35 + next.ServeHTTP(w, r) 36 + }) 37 + }
+46
internal/domain_redirect_test.go
··· 1 + package internal 2 + 3 + import ( 4 + "net/http" 5 + "net/http/httptest" 6 + "testing" 7 + ) 8 + 9 + func TestDomainRedirect(t *testing.T) { 10 + h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 11 + w.WriteHeader(http.StatusOK) 12 + }) 13 + 14 + t.Run("development", func(t *testing.T) { 15 + r := httptest.NewRequest("GET", "http://localhost/", nil) 16 + w := httptest.NewRecorder() 17 + 18 + DomainRedirect(h, true).ServeHTTP(w, r) 19 + 20 + if w.Code != http.StatusOK { 21 + t.Errorf("expected status 200, got %d", w.Code) 22 + } 23 + }) 24 + 25 + t.Run("redirect", func(t *testing.T) { 26 + r := httptest.NewRequest("GET", "http://example.com/", nil) 27 + w := httptest.NewRecorder() 28 + 29 + DomainRedirect(h, false).ServeHTTP(w, r) 30 + 31 + if w.Code != http.StatusMovedPermanently { 32 + t.Errorf("expected status 301, got %d", w.Code) 33 + } 34 + }) 35 + 36 + t.Run("allowed", func(t *testing.T) { 37 + r := httptest.NewRequest("GET", "http://example.com/blog.rss", nil) 38 + w := httptest.NewRecorder() 39 + 40 + DomainRedirect(h, false).ServeHTTP(w, r) 41 + 42 + if w.Code != http.StatusOK { 43 + t.Errorf("expected status 200, got %d", w.Code) 44 + } 45 + }) 46 + }