Config.purs 2.98 KB
Newer Older
1 2
module Gargantext.Config where

3 4 5 6
import Data.Array as A
import Data.Maybe (Maybe)
import Data.Array.NonEmpty as AN
import Data.NonEmpty (NonEmpty, (:|), head)
7
import Data.String as S
8 9
import Data.String.Utils as S
import Data.Tuple.Nested ((/\))
10
import Effect (Effect)
11 12 13

import Gargantext.Prelude (bind, pure, ($))

14 15
import Gargantext.Ends
import Gargantext.Types (ApiVersion(..))
16
import Gargantext.Utils (href)
Nicolas Pouillard's avatar
Nicolas Pouillard committed
17

James Laver's avatar
James Laver committed
18
defaultBackends :: NonEmpty Array Backend
James Laver's avatar
James Laver committed
19 20
defaultBackends =
 backend_local :| [ backend_prod, backend_partner, backend_demo, backend_dev ]
21

22 23
prodUrl :: String
prodUrl = "https://v4.gargantext.org"
24
backend_prod :: Backend
25
backend_prod    = backend V10 "/api/" prodUrl    "iscpif.cnrs"
26

27 28
partnerUrl :: String
partnerUrl = "https://imtv4.gargantext.org"
29
backend_partner :: Backend
30
backend_partner = backend V10 "/api/" partnerUrl "institut-mines-telecom.imt"
31

32 33
demoUrl :: String
demoUrl = "https://demo.gargantext.org"
34
backend_demo :: Backend
35
backend_demo    = backend V10 "/api/" demoUrl    "demo.inshs.cnrs"
36

37 38
devUrl :: String
devUrl = "https://dev.gargantext.org"
39
backend_dev :: Backend
40
backend_dev     = backend V10 "/api/" devUrl     "devel.inshs.cnrs"
41

42 43
localUrl :: String
localUrl = "http://localhost:8008"
44
backend_local :: Backend
45 46 47 48 49
backend_local   = backend V10 "/api/" localUrl   "local.cnrs"


matchCurrentLocation :: Effect (Maybe Backend)
matchCurrentLocation = do
50 51
  href <- href
  let starts = AN.filter (\(Backend { baseUrl }) -> S.startsWith baseUrl href) $ AN.fromNonEmpty defaultBackends
52
  pure $ A.head starts
53 54 55 56 57


-- | public Backend
-- When user is not logged, use the location of the window
publicBackend :: Backend
58
publicBackend = backend_local
59 60 61 62


publicBackend' :: Effect Backend
publicBackend' = do
63
  href <- href
64
  pure $ Backend { name  : "Public Backend"
65
                 , baseUrl : href
66 67 68 69
                 , prePath : "api/"
                 , version : V10
                 }

70

71
defaultApps :: NonEmpty Array Frontend
72
defaultApps = relative :| [prod, dev, demo, haskell, caddy]
James Laver's avatar
James Laver committed
73
  where
74 75 76
    relative = frontend "/#/" ""                            "Relative"
    prod     = frontend "/#/" "https://v4.gargantext.org"   "v4.gargantext.org"
    dev      = frontend "/#/" "https://dev.gargantext.org"  "gargantext.org (dev)"
77
    demo     = frontend "/#/" "https://demo.gargantext.org" "gargantext.org (demo)"
78 79 80
    haskell  = frontend "/#/" "http://localhost:8008"       "localhost.gargantext"
    python   = frontend "/#/" "http://localhost:8000"       "localhost.python"
    caddy    = frontend "/#/" "http://localhost:2015"       "localhost.caddy"
James Laver's avatar
James Laver committed
81 82 83 84 85 86

defaultStatics :: NonEmpty Array Frontend
defaultStatics = relative :| []
  where
    relative = frontend "" "/" "relative"

87 88
defaultApp :: Frontend
defaultApp = head defaultApps
89

90 91
defaultStatic :: Frontend
defaultStatic = head defaultStatics
92

93 94
defaultFrontends :: Frontends
defaultFrontends = Frontends { app: defaultApp, static: defaultStatic }
95

96 97 98 99
changePort :: String -> String
changePort = S.replace (S.Pattern "http://localhost:8000/") (S.Replacement "http://localhost:8008/")