on dacea01 help sign in
servant/src/Servant/Utils/StaticFiles.hs
33 lines 795 B history raw
1module Servant.Utils.StaticFiles (
2 serveDirectory,
3 serveDocumentation,
4 ) where
6import Data.Proxy
7import Data.String.Conversions
8import Filesystem.Path.CurrentOS (decodeString)
9import Network.HTTP.Types
10import Network.Wai
11import Network.Wai.Application.Static
13import Servant.API
14import Servant.Docs
15import Servant.Server
17serveDirectory :: FilePath -> Server Raw
18serveDirectory documentRoot =
19 staticApp (defaultFileServerSettings (decodeString (documentRoot ++ "/")))
21serveDocumentation :: HasDocs api => Proxy api -> Server Raw
22serveDocumentation proxy _request respond =
23 respond $ responseLBS ok200 [] $ cs $ toHtml $ markdown $ docs proxy
25toHtml :: String -> String
26toHtml markdown =
27 "<html>" ++
28 "<body>" ++
29 "<pre>" ++
30 markdown ++
31 "</pre>" ++
32 "</body>" ++
33 "</html>"