Skip to content

Commit

Permalink
attempt at fixing cors
Browse files Browse the repository at this point in the history
  • Loading branch information
bristermitten committed Sep 12, 2024
1 parent 0bdbed7 commit 17f17d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions templatespiler-server/server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ common shared
, uuid
, wai
, wai-cors
, wai-extra
, warp

default-language: GHC2021
Expand Down
12 changes: 11 additions & 1 deletion templatespiler-server/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import Data.OpenApi.Internal.Utils (encodePretty)
import Data.UUID.V4 (nextRandom)
import Language.Templatespiler.Parser (parseBindingList)
import Language.Templatespiler.Syntax (BindingList)
import Network.Wai (Middleware)
import Network.Wai.Handler.Warp (run)
import Network.Wai.Middleware.Cors
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Options.Applicative qualified as Apt
import Prettyprinter
import Prettyprinter.Render.Text
Expand Down Expand Up @@ -52,7 +54,15 @@ main = do
)

app :: State -> Application
app s = simpleCors $ serve (Proxy @Api) $ hoistServer (Proxy @Api) (nt s) mainServer
app s = myCors $ logStdoutDev $ serve (Proxy @Api) $ hoistServer (Proxy @Api) (nt s) mainServer

myCors :: Middleware
myCors = cors (const $ Just policy)
where
policy =
simpleCorsResourcePolicy
{ corsRequestHeaders = ["Content-Type"]
}

nt :: State -> AppM a -> Handler a
nt s x = runReaderT x s
Expand Down

0 comments on commit 17f17d1

Please sign in to comment.