From c53c1b771f99b95323a226f896bafa51d96f318c Mon Sep 17 00:00:00 2001 From: David Nix Date: Sun, 12 Nov 2023 13:59:39 -0700 Subject: [PATCH] Add robots.txt --- server/routes.go | 11 ++++++++++- server/seo_test.go | 22 ++++++++++++++++++++++ server/views/robots.txt | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 server/seo_test.go create mode 100644 server/views/robots.txt diff --git a/server/routes.go b/server/routes.go index 7b88567..2ff8b46 100644 --- a/server/routes.go +++ b/server/routes.go @@ -1,16 +1,25 @@ package server import ( + _ "embed" "net/http" "github.com/DavidNix/indie/ent" "github.com/labstack/echo/v4" ) +//go:embed views/robots.txt +var robotstxt string + func addRoutes(app *echo.Echo, client *ent.Client) { + // SEO + // TODO: Change the sitemap URL. + app.GET("/robots.txt", func(c echo.Context) error { return c.String(http.StatusOK, robotstxt) }) + + // Routes app.GET("/", func(c echo.Context) error { return c.String(http.StatusOK, "Hello, World 👋!") }) - app.GET("/users", userIndexHandler(client)) + app.POST("/users", userCreateHandler(client)) } diff --git a/server/seo_test.go b/server/seo_test.go new file mode 100644 index 0000000..b9f010b --- /dev/null +++ b/server/seo_test.go @@ -0,0 +1,22 @@ +package server + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestRobotsTxt(t *testing.T) { + t.Parallel() + + app := NewApp(nil) + + req := httptest.NewRequest(http.MethodGet, "/robots.txt", nil) + w := httptest.NewRecorder() + app.ServeHTTP(w, req) + + require.Equal(t, 200, w.Code) + require.NotEmpty(t, w.Body.String()) +} diff --git a/server/views/robots.txt b/server/views/robots.txt new file mode 100644 index 0000000..7389f5c --- /dev/null +++ b/server/views/robots.txt @@ -0,0 +1,3 @@ +User-agent: * +Allow: / +Sitemap: https://changeme.com/sitemap.xml \ No newline at end of file