This package provides a Haskell implemenation of CORS for WAI that aims to be compliant with http://www.w3.org/TR/cors.
The file test/server.hs
shows how to support simple cross-origin requests (as
defined in http://www.w3.org/TR/cors) in a
scotty application.
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
module Main
( main
) where
import Network.Wai.Middleware.Cors
import Web.Scotty
main ∷ IO ()
main = scotty 8080 $ do
middleware simpleCors
matchAny "/" $ text "Success"
The result of following curl command will include the HTTP response
header Access-Control-Allow-Origin: *
.
curl -i http://127.0.0.1:8888 -H 'Origin: 127.0.0.1' -v
Documentation for more general usage can be found in the module Network.Wai.Middleware.Cors.
Currently there is only basic support to test simple cross-origin request from a browser.
Start server:
cd test
runHaskell server.hs
Open the file test/index.html
in a modern web-browser in order to run some
simple tests.