Serve /index.html contents on route /

parent 04186169
...@@ -77,6 +77,7 @@ library: ...@@ -77,6 +77,7 @@ library:
- attoparsec - attoparsec
- base >=4.7 && <5 - base >=4.7 && <5
- base16-bytestring - base16-bytestring
- blaze-html
- bytestring - bytestring
- case-insensitive - case-insensitive
- cassava - cassava
...@@ -136,6 +137,7 @@ library: ...@@ -136,6 +137,7 @@ library:
- semigroups - semigroups
- servant - servant
- servant-auth - servant-auth
- servant-blaze
- servant-client - servant-client
- servant-job - servant-job
- servant-mock - servant-mock
......
...@@ -56,11 +56,15 @@ import Network.Wai ...@@ -56,11 +56,15 @@ import Network.Wai
import Network.Wai.Handler.Warp hiding (defaultSettings) import Network.Wai.Handler.Warp hiding (defaultSettings)
import Servant import Servant
import Servant.HTML.Blaze (HTML)
import Servant.Mock (mock) import Servant.Mock (mock)
--import Servant.Job.Server (WithCallbacks) --import Servant.Job.Server (WithCallbacks)
import Servant.Static.TH.Internal.Server (fileTreeToServer)
import Servant.Static.TH.Internal.FileTree (fileTypeToFileTree, FileType(FileTypeFile))
import Servant.Swagger import Servant.Swagger
import Servant.Swagger.UI import Servant.Swagger.UI
-- import Servant.API.Stream -- import Servant.API.Stream
import Text.Blaze.Html (Html)
--import Gargantext.API.Swagger --import Gargantext.API.Swagger
import Gargantext.Prelude import Gargantext.Prelude
...@@ -258,17 +262,24 @@ type GargAPI' = ...@@ -258,17 +262,24 @@ type GargAPI' =
-- :<|> "ngrams" :> Capture "id" Int :> NodeAPI -- :<|> "ngrams" :> Capture "id" Int :> NodeAPI
-- :<|> "auth" :> Capture "id" Int :> NodeAPI -- :<|> "auth" :> Capture "id" Int :> NodeAPI
--------------------------------------------------------------------- ---------------------------------------------------------------------
type SwaggerFrontAPI = SwaggerAPI :<|> FrontEndAPI type SwaggerFrontAPI = SwaggerAPI :<|> FrontEndAPI
type API = SwaggerFrontAPI :<|> GargAPI :<|> Get '[HTML] Html
type API = SwaggerFrontAPI :<|> GargAPI
--------------------------------------------------------------------- ---------------------------------------------------------------------
-- | Server declaration -- | Server declarations
server :: Env -> IO (Server API) server :: Env -> IO (Server API)
server env = do server env = do
gargAPI <- serverGargAPI env
pure $ swaggerFront
:<|> gargAPI
:<|> serverIndex
serverGargAPI :: Env -> IO (Server GargAPI)
serverGargAPI env = do
-- orchestrator <- scrapyOrchestrator env -- orchestrator <- scrapyOrchestrator env
pure $ swaggerFront pure $ auth conn
:<|> auth conn
:<|> roots conn :<|> roots conn
:<|> nodeAPI conn (Proxy :: Proxy HyperdataAny) :<|> nodeAPI conn (Proxy :: Proxy HyperdataAny)
:<|> nodeAPI conn (Proxy :: Proxy HyperdataCorpus) :<|> nodeAPI conn (Proxy :: Proxy HyperdataCorpus)
...@@ -282,6 +293,10 @@ server env = do ...@@ -282,6 +293,10 @@ server env = do
where where
conn = env ^. env_conn conn = env ^. env_conn
serverIndex :: Server (Get '[HTML] Html)
serverIndex = $(do (Just s) <- liftIO (fileTypeToFileTree (FileTypeFile "purescript-gargantext/dist/index.html"))
fileTreeToServer s)
--------------------------------------------------------------------- ---------------------------------------------------------------------
swaggerFront :: Server SwaggerFrontAPI swaggerFront :: Server SwaggerFrontAPI
swaggerFront = schemaUiServer swaggerDoc swaggerFront = schemaUiServer swaggerDoc
...@@ -295,7 +310,7 @@ makeApp :: Env -> IO Application ...@@ -295,7 +310,7 @@ makeApp :: Env -> IO Application
makeApp = fmap (serve api) . server makeApp = fmap (serve api) . server
appMock :: Application appMock :: Application
appMock = serve api (swaggerFront :<|> gargMock) appMock = serve api (swaggerFront :<|> gargMock :<|> serverIndex)
--------------------------------------------------------------------- ---------------------------------------------------------------------
api :: Proxy API api :: Proxy API
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment