Commit 36f89667 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] backend public url (thx to James Laver aka dysfun)

parent a850d993
module Gargantext.Components.Nodes.Home.Public where module Gargantext.Components.Nodes.Home.Public where
import DOM.Simple.Console (log) import DOM.Simple.Console (log)
import Effect (Effect)
import Effect.Class (liftEffect)
import DOM.Simple.Window (window)
import FFI.Simple.Functions ((...), delay)
import Data.Tuple (fst) import Data.Tuple (fst)
import Data.Argonaut as Argonaut import Data.Argonaut as Argonaut
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
...@@ -13,9 +9,10 @@ import Data.Maybe (Maybe(..)) ...@@ -13,9 +9,10 @@ import Data.Maybe (Maybe(..))
import Data.NonEmpty (head) import Data.NonEmpty (head)
import Data.String (take) import Data.String (take)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Gargantext.Config (defaultBackends) import Effect.Class (liftEffect)
import Gargantext.Config (publicBackend)
import Gargantext.Config.REST (get) import Gargantext.Config.REST (get)
import Gargantext.Ends (backendUrl) import Gargantext.Ends (toUrl)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Utils.Argonaut (genericSumDecodeJson, genericSumEncodeJson) import Gargantext.Utils.Argonaut (genericSumDecodeJson, genericSumEncodeJson)
...@@ -56,16 +53,10 @@ type LoadData = () ...@@ -56,16 +53,10 @@ type LoadData = ()
type LoadProps = (reload :: Int) type LoadProps = (reload :: Int)
loadPublicData :: Record LoadProps -> Aff (Array PublicData) loadPublicData :: Record LoadProps -> Aff (Array PublicData)
--loadPublicData _l = get Nothing (backendUrl backend "public")
loadPublicData _l = do loadPublicData _l = do
-- let backend = head defaultBackends backend <- liftEffect publicBackend
let windowLocation = "localhost:8008/" _ <- liftEffect (log backend)
windowLocation' <- liftEffect (location {}) get Nothing (toUrl backend "public")
_ <- liftEffect $ log windowLocation'
get Nothing (windowLocation <> "public")
location :: forall a. a -> Effect String
location _ = window ... "location" $ []
renderPublic :: R.Element renderPublic :: R.Element
renderPublic = R.createElement renderPublicCpt {} [] renderPublic = R.createElement renderPublicCpt {} []
......
module Gargantext.Config where module Gargantext.Config where
import Data.String as S
import Web.HTML.Location (Location(..))
import Effect (Effect)
import Data.NonEmpty (NonEmpty, (:|), head) import Data.NonEmpty (NonEmpty, (:|), head)
import Gargantext.Ends import Gargantext.Ends
import Gargantext.Types (ApiVersion(..)) import Gargantext.Types (ApiVersion(..))
import Gargantext.Utils (location)
import Gargantext.Prelude (bind, pure, ($))
defaultBackends :: NonEmpty Array Backend defaultBackends :: NonEmpty Array Backend
defaultBackends = local :| [prod, partner, demo, dev] defaultBackends = local :| [prod, partner, demo, dev]
...@@ -38,3 +43,18 @@ defaultStatic = head defaultStatics ...@@ -38,3 +43,18 @@ defaultStatic = head defaultStatics
defaultFrontends :: Frontends defaultFrontends :: Frontends
defaultFrontends = Frontends { app: defaultApp, static: defaultStatic } defaultFrontends = Frontends { app: defaultApp, static: defaultStatic }
-- | public Backend
-- When user is not logged, use the location of the window
publicBackend :: Effect Backend
publicBackend = do
url <- location
pure $ Backend { name : "Public Backend"
, baseUrl : url
, prePath : "api/"
, version : V10
}
changePort :: String -> String
changePort = S.replace (S.Pattern "http://localhost:8000/") (S.Replacement "http://localhost:8008/")
module Gargantext.Utils where module Gargantext.Utils where
import Prelude import DOM.Simple.Window (window)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Lens (Lens', lens) import Data.Lens (Lens', lens)
import Data.Newtype (class Newtype, unwrap, wrap) import Data.Newtype (class Newtype, unwrap, wrap)
import Data.Set as Set
import Data.Set (Set) import Data.Set (Set)
import Data.Set as Set
import Data.String as S import Data.String as S
import Effect (Effect)
import Effect.Class (liftEffect)
import FFI.Simple ((..))
import FFI.Simple.Functions (delay)
import Prelude
-- | TODO (hard coded) -- | TODO (hard coded)
csrfMiddlewareToken :: String csrfMiddlewareToken :: String
...@@ -74,3 +79,10 @@ queryMatchesLabel q l = S.contains (S.Pattern $ normalize q) (normalize l) ...@@ -74,3 +79,10 @@ queryMatchesLabel q l = S.contains (S.Pattern $ normalize q) (normalize l)
mapLeft :: forall l m r. (l -> m) -> Either l r -> Either m r mapLeft :: forall l m r. (l -> m) -> Either l r -> Either m r
mapLeft f (Left l) = Left (f l) mapLeft f (Left l) = Left (f l)
mapLeft _ (Right r) = Right r mapLeft _ (Right r) = Right r
-- | Get current Window Location
location :: Effect String
location = delay unit $ \_ -> pure $ window .. "location"
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