Skip to content

A Haskell implementation of Cross-Origin resource sharing (CORS) for Wai

License

Notifications You must be signed in to change notification settings

alephcloud/wai-cors

Repository files navigation

Build Status

Cross-Origin Resource Sharing (CORS) For Wai

This package provides a Haskell implemenation of CORS for WAI that aims to be compliant with http://www.w3.org/TR/cors.

Usage

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.

TEST

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.

About

A Haskell implementation of Cross-Origin resource sharing (CORS) for Wai

Resources

License

Stars

Watchers

Forks

Packages

No packages published