From 6c1ab93717359f5823d0faf0e2dbe3ca317cad73 Mon Sep 17 00:00:00 2001 From: funkyduck Date: Thu, 14 Jan 2021 09:46:20 -0500 Subject: [PATCH] The gopher integration was not setting host or port, causing all links to break. This will derive the host from the configured host by stripping the protocol from the URI --- gopher.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gopher.go b/gopher.go index 30391f1..56d3fd6 100644 --- a/gopher.go +++ b/gopher.go @@ -14,6 +14,7 @@ import ( "bytes" "fmt" "io" + "regexp" "strings" "github.com/prologic/go-gopher" @@ -28,6 +29,11 @@ func initGopher(apper Apper) { gopher.ListenAndServe(fmt.Sprintf(":%d", apper.App().Config().Server.GopherPort), nil) } +// Utility function to strip the URL from the hostname provided by app.cfg.App.Host +func stripHostProtocol(app *App) string { + return string(regexp.MustCompile("^.*://").ReplaceAll([]byte(app.cfg.App.Host), []byte(""))) +} + func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error { parts := strings.Split(r.Selector, "/") if app.cfg.App.SingleUser { @@ -51,6 +57,8 @@ func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error { for _, c := range *colls { w.WriteItem(&gopher.Item{ + Host: stripHostProtocol(app), + Port: app.cfg.Server.GopherPort, Type: gopher.DIRECTORY, Description: c.DisplayTitle(), Selector: "/" + c.Alias + "/", @@ -99,6 +107,8 @@ func handleGopherCollection(app *App, w gopher.ResponseWriter, r *gopher.Request for _, p := range *posts { w.WriteItem(&gopher.Item{ + Port: app.cfg.Server.GopherPort, + Host: stripHostProtocol(app), Type: gopher.FILE, Description: p.CreatedDate() + " - " + p.DisplayTitle(), Selector: baseSel + p.Slug.String,