Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
158
Issues
158
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
360324bb
Commit
360324bb
authored
Mar 07, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[OPT] to activate or not the firewall/cors.
parent
b8c4d008
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
14 deletions
+10
-14
API.hs
src/Gargantext/API.hs
+10
-14
No files found.
src/Gargantext/API.hs
View file @
360324bb
...
...
@@ -91,32 +91,33 @@ import Network.HTTP.Types hiding (Query)
-- import Gargantext.API.Settings
fireWall
::
Applicative
f
=>
Request
->
f
Bool
fireWall
req
=
do
data
FireWall
=
FireWall
{
unFireWall
::
Bool
}
fireWall
::
Applicative
f
=>
Request
->
FireWall
->
f
Bool
fireWall
req
fw
=
do
let
origin
=
lookup
"Origin"
(
requestHeaders
req
)
let
host
=
lookup
"Host"
(
requestHeaders
req
)
let
hostOk
=
Just
(
encodeUtf8
"localhost:3000"
)
let
originOk
=
Just
(
encodeUtf8
"http://localhost:8008"
)
if
origin
==
originOk
&&
host
==
hostOk
if
origin
==
originOk
&&
host
==
hostOk
||
unFireWall
fw
then
pure
True
else
pure
False
-- makeApp :: Env -> IO (Warp.Settings, Application)
makeApp
::
IO
Application
makeApp
=
do
makeApp
::
FireWall
->
IO
Application
makeApp
fw
=
do
let
serverApp
=
appMock
-- logWare <- mkRequestLogger def { destination = RequestLogger.Logger $ env^.logger }
let
checkOriginAndHost
app
req
resp
=
do
blocking
<-
fireWall
req
blocking
<-
fireWall
req
fw
case
blocking
of
True
->
app
req
resp
False
->
app
req
resp
-- False -> resp ( responseLBS status401 [] "Invalid Origin or Host header" )
False
->
resp
(
responseLBS
status401
[]
"Invalid Origin or Host header"
)
let
corsMiddleware
=
cors
$
\
_
->
Just
CorsResourcePolicy
-- { corsOrigins = Just ([env^.settings.allowedOrigin], False)
...
...
@@ -138,11 +139,6 @@ makeApp = do
---------------------------------------------------------------------
type
PortNumber
=
Int
---------------------------------------------------------------------
...
...
@@ -268,7 +264,7 @@ startGargantextMock :: PortNumber -> IO ()
startGargantextMock
port
=
do
portRouteInfo
port
application
<-
makeApp
application
<-
makeApp
(
FireWall
False
)
run
port
application
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment