Skip to content

Commit

Permalink
demo: added robots.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Feb 12, 2024
1 parent fff3e77 commit 2fb1ffe
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions examples/full-app-gourmet/static/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

//go:embed *
var staticFiles embed.FS
var StaticFiles embed.FS

// Handler returns a http.Handler that will serve files from
// the given file system.
func Handler() http.Handler {
return http.FileServer(http.FS(staticFiles))
return http.FileServer(http.FS(StaticFiles))
}
1 change: 0 additions & 1 deletion examples/full-app-gourmet/static/embed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ func TestHandler(t *testing.T) {
}

t.Log(w.Body.String())
t.Fail()
})
}
3 changes: 3 additions & 0 deletions examples/full-app-gourmet/static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
User-agent: *
Allow: /
Disallow: /admin/
5 changes: 5 additions & 0 deletions examples/full-app-gourmet/views/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path"
"time"

"github.com/go-fuego/fuego/examples/full-app-gourmet/static"
"github.com/go-fuego/fuego/examples/full-app-gourmet/store"
"github.com/go-fuego/fuego/examples/full-app-gourmet/templa"

Expand Down Expand Up @@ -43,6 +44,10 @@ func (rs Ressource) showRecipesStd(w http.ResponseWriter, r *http.Request) {
}
}

func (rs Ressource) robots(w http.ResponseWriter, r *http.Request) {
http.ServeFileFS(w, r, static.StaticFiles, "robots.txt")
}

func (rs Ressource) showIndex(c fuego.ContextNoBody) (fuego.Templ, error) {
timeDBRequest := time.Now()

Expand Down
1 change: 1 addition & 0 deletions examples/full-app-gourmet/views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func (rs Ressource) Routes(s *fuego.Server) {
// Public Pages
fuego.GetStd(s, "/recipes-std", rs.showRecipesStd)
fuego.Get(s, "/", rs.showIndex, cache.New())
fuego.GetStd(s, "/robots.txt", rs.robots, cache.New())
fuego.Get(s, "/recipes", rs.showRecipes)
fuego.Get(s, "/planner", rs.planner)
fuego.Get(s, "/recipes/{id}", rs.showSingleRecipes2)
Expand Down

0 comments on commit 2fb1ffe

Please sign in to comment.