Skip to content

Commit

Permalink
Add cors headers (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
colll78 authored Jan 8, 2025
1 parent f0286ca commit 52c6ed2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lib/Wst/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Convex.CardanoApi.Lenses qualified as L
import Convex.Class (MonadBlockchain, MonadUtxoQuery)
import Data.Data (Proxy (..))
import Network.Wai.Handler.Warp qualified as Warp
import Network.Wai.Middleware.Cors
import PlutusTx.Prelude qualified as P
import Servant (Server, ServerT)
import Servant.API (NoContent (..), Raw, (:<|>) (..))
Expand Down Expand Up @@ -58,7 +59,7 @@ defaultServerArgs =

runServer :: (Env.HasRuntimeEnv env, Env.HasDirectoryEnv env) => env -> ServerArgs -> IO ()
runServer env ServerArgs{saPort, saStaticFiles} = do
let app = case saStaticFiles of
let app = cors (const $ Just simpleCorsResourcePolicy) $ case saStaticFiles of
Nothing -> serve (Proxy @APIInEra) (server env)
Just fp -> serve (Proxy @CombinedAPI) (server env :<|> serveDirectoryWebApp fp)
port = saPort
Expand Down
3 changes: 2 additions & 1 deletion src/test/lib/Wst/Test/MockServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Cardano.Api qualified as C
import Control.Monad.IO.Class (MonadIO (..))
import Data.Proxy (Proxy (..))
import Network.Wai.Handler.Warp qualified as Warp
import Network.Wai.Middleware.Cors
import Servant (Server)
import Servant.API (NoContent (..), (:<|>) (..))
import Servant.Server (serve)
Expand Down Expand Up @@ -46,7 +47,7 @@ mockTxApi =
-- | Start the mock server
runMockServer :: IO ()
runMockServer = do
let app = serve (Proxy @APIInEra) mockServer
let app = simpleCors $ serve (Proxy @APIInEra) mockServer
port = 8080
putStrLn $ "Starting mock server on port " <> show port
Warp.run port app
2 changes: 2 additions & 0 deletions src/wst-poc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ library
, servant-client-core
, servant-server
, text
, wai-cors
, warp

hs-source-dirs: lib
Expand Down Expand Up @@ -165,6 +166,7 @@ library test-lib
, QuickCheck
, servant
, servant-server
, wai-cors
, warp
, wst-poc

Expand Down

0 comments on commit 52c6ed2

Please sign in to comment.