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

3 4
import Data.Array as A
import Data.Array.NonEmpty as AN
Alexandre Delanoë's avatar
Alexandre Delanoë committed
5
import Data.Maybe (Maybe)
6
import Data.NonEmpty (NonEmpty, (:|), head)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
7 8
import Data.String (Pattern(..), Replacement(..), replace) as S
import Data.String.Utils (startsWith) as S
9
import Effect (Effect)
10
import Gargantext.Ends
Alexandre Delanoë's avatar
Alexandre Delanoë committed
11
import Gargantext.Prelude (bind, pure, ($))
12
import Gargantext.Types (ApiVersion(..))
13
import Gargantext.Utils (href)
Nicolas Pouillard's avatar
Nicolas Pouillard committed
14

15 16


17
defaultBackends :: NonEmpty Array Backend
Alexandre Delanoë's avatar
Alexandre Delanoë committed
18
defaultBackends =   backend' "Demo"            "Public Show room"          "https://demo.gargantext.org"
Alexandre Delanoë's avatar
Alexandre Delanoë committed
19
               :| [ backend' "Education"       "Training/Formation"        "https://formation.gargantext.org"
20 21
                  , backend' "Academia"        "Academia"                  "https://academia.sub.gargantext.org"
                  , backend' "Organization"    "CNRS"                      "https://cnrs.gargantext.org"
Alexandre Delanoë's avatar
Alexandre Delanoë committed
22
                  , backend' "Organization"    "Mines Telecom Institute"   "https://imt.sub.gargantext.org"
23
                  , backend' "Organization"    "Hello Word Company"        "https://helloword.gargantext.org"
24
                  , backend' "Community"       "Complex Systems"           "https://complexsystems.gargantext.org"
25
                  , backend' "Networking"      "European Projects"         "https://europa.gargantext.org"
26 27 28
                  , backend' "Community"       "Earth"                     "https://earth.sub.gargantext.org"
                  , backend' "Community"       "Health"                    "https://health.sub.gargantext.org"
                  , backend' "Community"       "MSH"                       "https://msh.sub.gargantext.org"
29
                  , backend' "Development"     "Main SandBox"              "https://dev.sub.gargantext.org"
30
                  , backend' "Private"         "Offline Bunker"            "http://localhost:8008"
31 32
                  ]
 
33

34
  where
35
    backend' t n u = backend t n V10 "/api/" u
36

37 38 39

matchCurrentLocation :: Effect (Maybe Backend)
matchCurrentLocation = do
40 41
  href <- href
  let starts = AN.filter (\(Backend { baseUrl }) -> S.startsWith baseUrl href) $ AN.fromNonEmpty defaultBackends
42
  pure $ A.head starts
43 44 45 46 47


-- | public Backend
-- When user is not logged, use the location of the window
publicBackend :: Backend
48
publicBackend = backend "Private" "local" V10 "/api/" "http://localhost:8008"
49 50 51

publicBackend' :: Effect Backend
publicBackend' = do
52
  href <- href
53
  pure $ Backend { name  : "Public Backend"
54
                 , baseUrl : href
55 56
                 , prePath : "api/"
                 , version : V10
57
                 , backendType : "Public home"
58 59
                 }

60
defaultApps :: NonEmpty Array Frontend
Alexandre Delanoë's avatar
Alexandre Delanoë committed
61
defaultApps = relative :| [prod, dev, demo, haskell, python, caddy]
James Laver's avatar
James Laver committed
62
  where
63 64
    relative = frontend "/#/" ""                            "Relative"
    prod     = frontend "/#/" "https://v4.gargantext.org"   "v4.gargantext.org"
65
    dev      = frontend "/#/" "https://dev.sub.gargantext.org"  "gargantext.org (dev)"
66
    demo     = frontend "/#/" "https://demo.gargantext.org" "gargantext.org (demo)"
67 68 69
    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
70 71 72 73 74 75

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

76 77
defaultApp :: Frontend
defaultApp = head defaultApps
78

79 80
defaultStatic :: Frontend
defaultStatic = head defaultStatics
81

82 83
defaultFrontends :: Frontends
defaultFrontends = Frontends { app: defaultApp, static: defaultStatic }
84

85 86 87
changePort :: String -> String
changePort = S.replace (S.Pattern "http://localhost:8000/") (S.Replacement "http://localhost:8008/")