Skip to content

Commit

Permalink
add robots.txt and meta tag (#276)
Browse files Browse the repository at this point in the history
* add robots.txt and meta tag

* critical typo 🤦
  • Loading branch information
drewhammond authored Nov 23, 2023
1 parent eb4ac48 commit 874ac70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions internal/app/ui/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ func (s *Service) RegisterRoutes() {
return c.Redirect(http.StatusFound, urlWithBasePath("/ui/nodes"))
})

s.engine.GET("/robots.txt", ViteHandler(""))

s.engine.RouteNotFound("/*", func(c echo.Context) error {
return c.Render(http.StatusNotFound, "errors/404", echo.Map{
"message": "Invalid route!",
})
})

router := s.engine.Group(urlWithBasePath("/ui"))
router := s.engine.Group(vCfg.Base)
{
router.GET("/", func(c echo.Context) error {
return c.Redirect(http.StatusFound, urlWithBasePath("/ui/nodes"))
Expand Down Expand Up @@ -149,8 +151,8 @@ func (s *Service) RegisterRoutes() {
router.GET("/policy-groups", s.getPolicyGroups)
router.GET("/policy-groups/:name", s.getPolicyGroup)

router.GET("/assets/*", ViteHandler(), CacheControlMiddleware)
router.GET("/favicons/*", ViteHandler(), CacheControlMiddleware)
router.GET("/assets/*", ViteHandler(vCfg.Base), CacheControlMiddleware)
router.GET("/favicons/*", ViteHandler(vCfg.Base), CacheControlMiddleware)
}
}

Expand All @@ -164,9 +166,9 @@ func CacheControlMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
}
}

func ViteHandler() echo.HandlerFunc {
func ViteHandler(prefix string) echo.HandlerFunc {
fs := http.FS(viteFS)
h := http.StripPrefix(urlWithBasePath("/ui"), http.FileServer(fs))
h := http.StripPrefix(prefix, http.FileServer(fs))
return echo.WrapHandler(h)
}

Expand Down
2 changes: 2 additions & 0 deletions ui/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /
1 change: 1 addition & 0 deletions ui/templates/layouts/master.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="same-origin">
<meta name="robots" content="noindex,nofollow">
<title>{{ block "title" . }}{{ .title }} · Chef Browser{{ end }}</title>
<script>
(() => {
Expand Down

0 comments on commit 874ac70

Please sign in to comment.