Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Bundle a default `/robots.txt` in static content (#3096)

Dan Fabuliche3499cf72215
diff --git a/cmd/handlers.go b/cmd/handlers.go
index 16cbd895..040b94a6 100644
--- a/cmd/handlers.go
+++ b/cmd/handlers.go
@@ -290,6 +290,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
// Public health API endpoint.
g.GET("/health", a.HealthCheck)
+ g.GET("/robots.txt", a.RobotsTxt)
// 404 pages.
g.RouteNotFound("/*", func(c echo.Context) error {
@@ -322,6 +323,15 @@ func (a *App) HealthCheck(c echo.Context) error {
return c.JSON(http.StatusOK, okResp{true})
}
+// RobotsTxt serves the robots.txt file from the static filesystem.
+func (a *App) RobotsTxt(c echo.Context) error {
+ b, err := a.fs.Read("/public/static/robots.txt")
+ if err != nil {
+ return echo.NewHTTPError(http.StatusNotFound, "robots.txt not found")
+ }
+ return c.Blob(http.StatusOK, "text/plain; charset=utf-8", b)
+}
+
// serveCustomAppearance serves the given custom CSS/JS appearance blob
// meant for customizing public and admin pages from the admin settings UI.
func serveCustomAppearance(name string) echo.HandlerFunc {
diff --git a/static/public/static/robots.txt b/static/public/static/robots.txt
new file mode 100644
index 00000000..da9f2ecc
--- /dev/null
+++ b/static/public/static/robots.txt
@@ -0,0 +1,5 @@
+User-agent: *
+Allow: /subscription/form
+Disallow: /subscription/
+Disallow: /campaign/
+Disallow: /link/