Commit 360324bb authored by Alexandre Delanoë's avatar Alexandre Delanoë

[OPT] to activate or not the firewall/cors.

parent b8c4d008
...@@ -91,32 +91,33 @@ import Network.HTTP.Types hiding (Query) ...@@ -91,32 +91,33 @@ import Network.HTTP.Types hiding (Query)
-- import Gargantext.API.Settings -- import Gargantext.API.Settings
fireWall :: Applicative f => Request -> f Bool data FireWall = FireWall { unFireWall :: Bool }
fireWall req = do
fireWall :: Applicative f => Request -> FireWall -> f Bool
fireWall req fw = do
let origin = lookup "Origin" (requestHeaders req) let origin = lookup "Origin" (requestHeaders req)
let host = lookup "Host" (requestHeaders req) let host = lookup "Host" (requestHeaders req)
let hostOk = Just (encodeUtf8 "localhost:3000") let hostOk = Just (encodeUtf8 "localhost:3000")
let originOk = Just (encodeUtf8 "http://localhost:8008") let originOk = Just (encodeUtf8 "http://localhost:8008")
if origin == originOk && host == hostOk if origin == originOk && host == hostOk || unFireWall fw
then pure True then pure True
else pure False else pure False
-- makeApp :: Env -> IO (Warp.Settings, Application) -- makeApp :: Env -> IO (Warp.Settings, Application)
makeApp :: IO Application makeApp :: FireWall -> IO Application
makeApp = do makeApp fw = do
let serverApp = appMock let serverApp = appMock
-- logWare <- mkRequestLogger def { destination = RequestLogger.Logger $ env^.logger } -- logWare <- mkRequestLogger def { destination = RequestLogger.Logger $ env^.logger }
let checkOriginAndHost app req resp = do let checkOriginAndHost app req resp = do
blocking <- fireWall req blocking <- fireWall req fw
case blocking of case blocking of
True -> app req resp 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 let corsMiddleware = cors $ \_ -> Just CorsResourcePolicy
-- { corsOrigins = Just ([env^.settings.allowedOrigin], False) -- { corsOrigins = Just ([env^.settings.allowedOrigin], False)
...@@ -138,11 +139,6 @@ makeApp = do ...@@ -138,11 +139,6 @@ makeApp = do
--------------------------------------------------------------------- ---------------------------------------------------------------------
type PortNumber = Int type PortNumber = Int
--------------------------------------------------------------------- ---------------------------------------------------------------------
...@@ -268,7 +264,7 @@ startGargantextMock :: PortNumber -> IO () ...@@ -268,7 +264,7 @@ startGargantextMock :: PortNumber -> IO ()
startGargantextMock port = do startGargantextMock port = do
portRouteInfo port portRouteInfo port
application <-makeApp application <- makeApp (FireWall False)
run port application run port application
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment