diff --git a/CHANGELOG.md b/CHANGELOG.md index 5799e1411ee..7ff39f322d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ changes. - Add `GET /snapshot/utxo` API endpoint to query confirmed UTxO set on demand. - Always responds with the last confirmed UTxO +- Set [CORS](https://fetch.spec.whatwg.org/#http-cors-protocol) headers on `hydra-node` API to allow requests from any origin `*`. + - _DEPRECATED_ the `GetUTxO` client input and `GetUTxOResponse` server output. Use `GET /snapshot/utxo` instead. - `hydra-node` logs will now report `NetworkEvents` to distinguish between `ConnectivityEvent`s and `ReceivedMessage`s on the network. diff --git a/hydra-node/hydra-node.cabal b/hydra-node/hydra-node.cabal index 588888a1a72..6c98513fd3b 100644 --- a/hydra-node/hydra-node.cabal +++ b/hydra-node/hydra-node.cabal @@ -170,6 +170,7 @@ library , unliftio , vector , wai + , wai-cors , wai-websockets , warp , websockets diff --git a/hydra-node/src/Hydra/API/Server.hs b/hydra-node/src/Hydra/API/Server.hs index 96e02f7dc1e..8e8a7143248 100644 --- a/hydra-node/src/Hydra/API/Server.hs +++ b/hydra-node/src/Hydra/API/Server.hs @@ -41,6 +41,7 @@ import Network.Wai.Handler.Warp ( setPort, ) import Network.Wai.Handler.WebSockets (websocketsOr) +import Network.Wai.Middleware.Cors (simpleCors) import Network.WebSockets ( defaultConnectionOptions, ) @@ -93,8 +94,9 @@ withAPIServer host port party PersistenceIncremental{loadAll, append} tracer cha race_ ( do traceWith tracer (APIServerStarted port) - runSettings serverSettings $ - websocketsOr + runSettings serverSettings + . simpleCors + $ websocketsOr defaultConnectionOptions (wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel) (httpApp tracer chain pparams (atomically $ getLatest headIdP) (atomically $ getLatest snapshotUtxoP))