I am using servant-options packages as described in the documentation:
type RepositoryAPI = "repository" :> Get '[JSON] Repository
getRepository :: Handler Repository
getRepository = do
repository <- liftIO loadRawRepositoryFromFilesystem
return repository
server :: Server RepositoryAPI
server = getRepository
repositoryAPI :: Proxy RepositoryAPI
repositoryAPI = Proxy
app :: Application
app = logStdoutDev
$ cors (const $ Just policy)
$ provideOptions repositoryAPI
$ serve repositoryAPI server
where policy = simpleCorsResourcePolicy {
corsMethods = ["OPTIONS", "GET", "PUT", "POST"],
corsRequestHeaders = [ "Authorization", "Content-Type" ]
}
main :: IO ()
main = run 8081 app
But OPTIONS request to the URL still returns error 400:
OPTIONS /repository
Accept: */*
Status: 400 Bad Request 0.000039136s
What am I doing wrong? Tried with different policy configurations (no "Authorization" or no corsMethods or with lower case "content-type"), but still no luck. Could this be something I need to handle on the front-end? Any advice is appreciated.