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
145
Issues
145
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
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
d6d1cb30
Unverified
Commit
d6d1cb30
authored
Apr 09, 2018
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an environment type to hold the connection and the firewall settings
parent
59b24211
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
15 deletions
+32
-15
API.hs
src/Gargantext/API.hs
+32
-15
No files found.
src/Gargantext/API.hs
View file @
d6d1cb30
...
...
@@ -40,7 +40,7 @@ import Gargantext.Prelude
import
System.IO
(
FilePath
,
print
)
import
GHC.Generics
(
D1
,
Meta
(
..
),
Rep
)
import
GHC.Generics
(
D1
,
Meta
(
..
),
Rep
,
Generic
)
import
GHC.TypeLits
(
AppendSymbol
,
Symbol
)
import
Control.Lens
...
...
@@ -94,6 +94,17 @@ import Network.HTTP.Types hiding (Query)
data
FireWall
=
FireWall
{
unFireWall
::
Bool
}
data
GEnv
conn
=
Env
{
_env_conn
::
!
conn
,
_env_firewall
::
!
FireWall
}
deriving
(
Generic
)
makeLenses
''
G
Env
type
ProdEnv
=
GEnv
Connection
type
MockEnv
=
GEnv
()
fireWall
::
Applicative
f
=>
Request
->
FireWall
->
f
Bool
fireWall
req
fw
=
do
let
origin
=
lookup
"Origin"
(
requestHeaders
req
)
...
...
@@ -111,14 +122,14 @@ fireWall req fw = do
-- makeApp :: Env -> IO (Warp.Settings, Application)
makeApp
::
FireWall
->
IO
Application
makeApp
fw
=
do
makeApp
::
MockEnv
->
IO
Application
makeApp
env
=
do
let
serverApp
=
appMock
-- logWare <- mkRequestLogger def { destination = RequestLogger.Logger $ env^.logger }
--logWare <- mkRequestLogger def { destination = RequestLogger.Logger "/tmp/logs.txt" }
let
checkOriginAndHost
app
req
resp
=
do
blocking
<-
fireWall
req
fw
blocking
<-
fireWall
req
(
env
^.
env_firewall
)
case
blocking
of
True
->
app
req
resp
False
->
resp
(
responseLBS
status401
[]
...
...
@@ -183,13 +194,16 @@ type API = SwaggerFrontAPI :<|> GargAPI
---------------------------------------------------------------------
-- | Server declaration
server
::
Connection
->
Server
API
server
conn
=
swaggerFront
:<|>
roots
conn
:<|>
nodeAPI
conn
:<|>
nodeAPI
conn
:<|>
nodesAPI
conn
:<|>
count
server
::
ProdEnv
->
Server
API
server
env
=
swaggerFront
:<|>
roots
conn
:<|>
nodeAPI
conn
:<|>
nodeAPI
conn
:<|>
nodesAPI
conn
:<|>
count
where
conn
=
env
^.
env_conn
---------------------------------------------------------------------
swaggerFront
::
Server
SwaggerFrontAPI
...
...
@@ -200,8 +214,9 @@ gargMock :: Server GargAPI
gargMock
=
mock
apiGarg
Proxy
---------------------------------------------------------------------
app
::
Connection
->
Application
app
=
serve
api
.
server
app
::
ProdEnv
->
Application
app
=
serve
api
.
server
-- TODO firewall
appMock
::
Application
appMock
=
serve
api
(
swaggerFront
:<|>
gargMock
)
...
...
@@ -261,15 +276,17 @@ startGargantext port file = do
param
<-
databaseParameters
file
conn
<-
connect
param
let
env
=
Env
conn
(
FireWall
False
)
portRouteInfo
port
run
port
(
app
conn
)
run
port
(
app
env
)
startGargantextMock
::
PortNumber
->
IO
()
startGargantextMock
port
=
do
portRouteInfo
port
let
env
=
Env
()
(
FireWall
False
)
application
<-
makeApp
(
FireWall
False
)
application
<-
makeApp
env
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