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
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.Argonaut as Argonaut
import Data.Generic.Rep (class Generic)
......@@ -13,9 +9,10 @@ import Data.Maybe (Maybe(..))
import Data.NonEmpty (head)
import Data.String (take)
import Effect.Aff (Aff)
import Gargantext.Config (defaultBackends)
import Effect.Class (liftEffect)
import Gargantext.Config (publicBackend)
import Gargantext.Config.REST (get)
import Gargantext.Ends (backendUrl)
import Gargantext.Ends (toUrl)
import Gargantext.Prelude
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Utils.Argonaut (genericSumDecodeJson, genericSumEncodeJson)
......@@ -56,16 +53,10 @@ type LoadData = ()
type LoadProps = (reload :: Int)
loadPublicData :: Record LoadProps -> Aff (Array PublicData)
--loadPublicData _l = get Nothing (backendUrl backend "public")
loadPublicData _l = do
-- let backend = head defaultBackends
let windowLocation = "localhost:8008/"
windowLocation' <- liftEffect (location {})
_ <- liftEffect $ log windowLocation'
get Nothing (windowLocation <> "public")
location :: forall a. a -> Effect String
location _ = window ... "location" $ []
backend <- liftEffect publicBackend
_ <- liftEffect (log backend)
get Nothing (toUrl backend "public")
renderPublic :: R.Element
renderPublic = R.createElement renderPublicCpt {} []
......
module Gargantext.Config where
import Data.String as S
import Web.HTML.Location (Location(..))
import Effect (Effect)
import Data.NonEmpty (NonEmpty, (:|), head)
import Gargantext.Ends
import Gargantext.Types (ApiVersion(..))
import Gargantext.Utils (location)
import Gargantext.Prelude (bind, pure, ($))
defaultBackends :: NonEmpty Array Backend
defaultBackends = local :| [prod, partner, demo, dev]
......@@ -38,3 +43,18 @@ defaultStatic = head defaultStatics
defaultFrontends :: Frontends
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
import Prelude
import DOM.Simple.Window (window)
import Data.Either (Either(..))
import Data.Lens (Lens', lens)
import Data.Newtype (class Newtype, unwrap, wrap)
import Data.Set as Set
import Data.Set (Set)
import Data.Set as Set
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)
csrfMiddlewareToken :: String
......@@ -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 f (Left l) = Left (f l)
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