Config.purs 3.29 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"
19 20
               :| [ backend' "Education"       "Class Rooms"               "https://formation.gargantext.org"
                  , backend' "Organization"    "CNRS/ISCPIF Unit"          "https://cnrs.gargantext.org"
Alexandre Delanoë's avatar
Alexandre Delanoë committed
21
                  , backend' "Organization"    "Mines Telecom Institute"   "https://imt.sub.gargantext.org"
22
                  , backend' "Organization"    "Hello Word Company"        "https://helloword.gargantext.org"
23
                  , backend' "Networking"      "Complex Systems Community" "https://complexsystems.gargantext.org"
24
                  , backend' "Networking"      "European Projects"         "https://europa.gargantext.org"
25
                  , backend' "Development"     "Main SandBox"              "https://dev.sub.gargantext.org"
26
                  , backend' "Private"         "Offline Bunker"            "http://localhost:8008"
27 28
                  ]
 
29

30
  where
31
    backend' t n u = backend t n V10 "/api/" u
32

33 34 35

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


-- | public Backend
-- When user is not logged, use the location of the window
publicBackend :: Backend
44
publicBackend = backend "Private" "local" V10 "/api/" "http://localhost:8008"
45 46 47

publicBackend' :: Effect Backend
publicBackend' = do
48
  href <- href
49
  pure $ Backend { name  : "Public Backend"
50
                 , baseUrl : href
51 52
                 , prePath : "api/"
                 , version : V10
53
                 , backendType : "Public home"
54 55
                 }

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

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

72 73
defaultApp :: Frontend
defaultApp = head defaultApps
74

75 76
defaultStatic :: Frontend
defaultStatic = head defaultStatics
77

78 79
defaultFrontends :: Frontends
defaultFrontends = Frontends { app: defaultApp, static: defaultStatic }
80

81 82 83
changePort :: String -> String
changePort = S.replace (S.Pattern "http://localhost:8000/") (S.Replacement "http://localhost:8008/")