문제

I'm writing a client for my Yesod JSON server in angular.js. When examining the header traffic, it appears that Chrome is sending an OPTIONS method, which my handler rejects. Investigation suggests that I should send back something like this:

Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://source.com
Access-Control-Allow-Headers: Content-Type, *

Looking at the scaffolding, I find that makeApplication begins a trail I want to follow:

makeApplication :: AppConfig DefaultEnv Extra -> IO Application
makeApplication conf = do
    foundation <- makeFoundation conf
    app <- toWaiAppPlain foundation
    return $ logWare app
  where
    logWare   = if development then logStdoutDev
                               else logStdout

Initially, I thought I needed to modify conf, but from what I can understand that manages the OS environment. Where is the most straight-forward place to globally alter response headers?

도움이 되었습니까?

해결책

Probably the simplest thing is to add another middleware in addition to logWare.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top