Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PaymentServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
PaymentServer
Commits
fe3b43e7
Commit
fe3b43e7
authored
5 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Use wai-cors to apply a CORS policy across the whole API
parent
ad05b33c
No related branches found
Branches containing commit
No related tags found
1 merge request
!39
CORS headers on Stripe charge API responses
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/PaymentServer/Main.hs
+11
-1
11 additions, 1 deletion
src/PaymentServer/Main.hs
src/PaymentServer/Server.hs
+21
-5
21 additions, 5 deletions
src/PaymentServer/Server.hs
with
32 additions
and
6 deletions
src/PaymentServer/Main.hs
+
11
−
1
View file @
fe3b43e7
...
...
@@ -31,6 +31,9 @@ import Network.Wai.Handler.WarpTLS
import
Network.Wai
(
Application
)
import
Network.Wai.Middleware.Cors
(
Origin
)
import
Network.Wai.Middleware.RequestLogger
(
OutputFormat
(
Detailed
)
,
outputFormat
...
...
@@ -55,6 +58,7 @@ import Options.Applicative
,
option
,
auto
,
str
,
many
,
optional
,
long
,
help
...
...
@@ -93,6 +97,7 @@ data ServerConfig = ServerConfig
,
databasePath
::
Maybe
Text
,
endpoint
::
Endpoint
,
stripeKeyPath
::
FilePath
,
corsOrigins
::
[
Origin
]
}
deriving
(
Show
,
Eq
)
...
...
@@ -165,6 +170,9 @@ sample = ServerConfig
<*>
option
str
(
long
"stripe-key-path"
<>
help
"Path to Stripe Secret key"
)
<*>
many
(
option
str
(
long
"cors-origin"
<>
help
"An allowed `Origin` for the purposes of CORS (zero or more)."
)
)
opts
::
ParserInfo
ServerConfig
opts
=
info
(
sample
<**>
helper
)
...
...
@@ -230,6 +238,8 @@ getApp config =
Right
getDB
->
do
db
<-
getDB
key
<-
B
.
readFile
(
stripeKeyPath
config
)
let
app
=
paymentServerApp
key
issuer
db
let
origins
=
corsOrigins
config
app
=
paymentServerApp
origins
key
issuer
db
logger
<-
mkRequestLogger
(
def
{
outputFormat
=
Detailed
True
})
return
$
logger
app
This diff is collapsed.
Click to expand it.
src/PaymentServer/Server.hs
+
21
−
5
View file @
fe3b43e7
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-}
-- | This module exposes a Servant-based Network.Wai server for payment
-- interactions.
...
...
@@ -8,7 +9,10 @@ module PaymentServer.Server
)
where
import
Network.Wai.Middleware.Cors
(
simpleCors
(
Origin
,
CorsResourcePolicy
(
corsOrigins
,
corsMethods
,
corsRequestHeaders
)
,
simpleCorsResourcePolicy
,
cors
)
import
Servant
(
Proxy
(
Proxy
)
...
...
@@ -50,10 +54,22 @@ paymentServerAPI = Proxy
-- | Create a Servant Application which serves the payment server API using
-- the given database.
paymentServerApp
::
VoucherDatabase
d
=>
StripeSecretKey
->
Issuer
->
d
->
Application
paymentServerApp
key
issuer
=
paymentServerApp
::
VoucherDatabase
d
=>
[
Origin
]
-- ^ A list of CORS Origins to accept.
->
StripeSecretKey
->
Issuer
->
d
->
Application
paymentServerApp
corsOrigins
key
issuer
=
let
app
=
serve
paymentServerAPI
.
paymentServer
key
issuer
cors
=
simpleCors
withCredentials
=
False
corsResourcePolicy
=
simpleCorsResourcePolicy
{
corsOrigins
=
Just
(
corsOrigins
,
withCredentials
)
,
corsMethods
=
[
"POST"
]
,
corsRequestHeaders
=
[
"Content-Type"
]
}
cors'
=
cors
(
const
$
Just
corsResourcePolicy
)
in
cors
.
app
cors
'
.
app
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment