Skip to content

Commit

Permalink
Add robots.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidNix committed Nov 12, 2023
1 parent 560976a commit c53c1b7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/routes.go
Original file line number Diff line number Diff line change
@@ -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))
}
22 changes: 22 additions & 0 deletions server/seo_test.go
Original file line number Diff line number Diff line change
@@ -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())
}
3 changes: 3 additions & 0 deletions server/views/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
User-agent: *
Allow: /
Sitemap: https://changeme.com/sitemap.xml

0 comments on commit c53c1b7

Please sign in to comment.