From ea1b7b5c43810bbb6d155415720bf7d98ca95bec Mon Sep 17 00:00:00 2001 From: David Johnson Date: Wed, 20 Nov 2024 16:13:47 -0600 Subject: [PATCH] Add robots.txt to haskell-miso.org --- examples/haskell-miso.org/server/Main.hs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/haskell-miso.org/server/Main.hs b/examples/haskell-miso.org/server/Main.hs index bb3afb6..7a1c77e 100644 --- a/examples/haskell-miso.org/server/Main.hs +++ b/examples/haskell-miso.org/server/Main.hs @@ -38,13 +38,23 @@ main = do app :: Application #if MIN_VERSION_servant(0,11,0) -app = serve (Proxy @ API) (static :<|> serverHandlers :<|> pure misoManifest :<|> Tagged handle404) +app = serve (Proxy @ API) (static :<|> serverHandlers :<|> pure misoManifest :<|> pure robotsTxt :<|> Tagged handle404) #else -app = serve (Proxy @ API) (static :<|> serverHandlers :<|> pure misoManifest :<|> handle404) +app = serve (Proxy @ API) (static :<|> serverHandlers :<|> pure misoManifest :<|> pure robotsTxt :<|> handle404) #endif where static = serveDirectoryWith (defaultWebAppSettings "static") +robotsTxt :: Text +robotsTxt = + T.unlines + [ "# www.robotstxt.org/" + , "" + , "# Allow crawling of all content" + , "User-agent: *" + , "Disallow:" + ] + -- | Wrapper for setting HTML doctype and header newtype Wrapper a = Wrapper a deriving (Show, Eq) @@ -52,10 +62,14 @@ newtype Wrapper a = Wrapper a -- | Convert client side routes into server-side web handlers type ServerRoutes = ToServerRoutes ClientRoutes Wrapper Action +-- | robots.txt +type RobotsTXT = "robots.txt" :> Get '[PlainText] Text + -- | API type type API = ("static" :> Raw) :<|> ServerRoutes :<|> ("manifest.json" :> Get '[JSON] Manifest) + :<|> RobotsTXT :<|> Raw data Manifest