diff --git a/src/Swarm/Web.hs b/src/Swarm/Web.hs index 75605c4cf..9eee2a416 100644 --- a/src/Swarm/Web.hs +++ b/src/Swarm/Web.hs @@ -57,6 +57,7 @@ import Data.Tree (Tree (Node), drawTree) import Network.HTTP.Types (ok200) import Network.Wai (responseLBS) import Network.Wai qualified +import Network.Wai.Application.Static (defaultFileServerSettings, ssIndices) import Network.Wai.Handler.Warp qualified as Warp import Servant import Servant.Docs (ToCapture) @@ -82,6 +83,7 @@ import Swarm.TUI.Model.UI import Swarm.Util.RingBuffer import System.Timeout (timeout) import Text.Read (readEither) +import WaiAppStatic.Types (unsafeToPiece) import Witch (into) -- ------------------------------------------------------------------ @@ -108,7 +110,10 @@ type SwarmAPI = swarmApi :: Proxy SwarmAPI swarmApi = Proxy -type ToplevelAPI = SwarmAPI :<|> Raw +type ToplevelAPI = + SwarmAPI + :<|> "api" :> Raw + :<|> Raw api :: Proxy ToplevelAPI api = Proxy @@ -260,7 +265,10 @@ webMain baton port appStateRef chan = catch (Warp.runSettings settings app) hand Nothing -> id server :: Server ToplevelAPI - server = mkApp appStateRef chan :<|> Tagged serveDocs + server = + mkApp appStateRef chan + :<|> Tagged serveDocs + :<|> serveDirectoryWith (defaultFileServerSettings "web") {ssIndices = [unsafeToPiece "index.html"]} where serveDocs _ resp = resp $ responseLBS ok200 [plain] swarmApiHtml diff --git a/swarm.cabal b/swarm.cabal index 10bdb8544..43c88fe39 100644 --- a/swarm.cabal +++ b/swarm.cabal @@ -305,6 +305,7 @@ library prettyprinter >= 1.7.0 && < 1.8, random >= 1.2.0 && < 1.3, scientific >= 0.3.6 && < 0.3.8, + wai-app-static >= 3.1.8 && < 3.1.9, servant >= 0.19 && < 0.21, servant-docs >= 0.12 && < 0.14, servant-server >= 0.19 && < 0.21, diff --git a/web/index.html b/web/index.html new file mode 100644 index 000000000..3293ce3d8 --- /dev/null +++ b/web/index.html @@ -0,0 +1,10 @@ + + +
+Looking for the Web API docs?
+ + \ No newline at end of file