]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-server/Main.hs
[SECURITY] Prod mode preserves confidentiality of passwords now. (Use Dev for debug...
[gargantext.git] / bin / gargantext-server / Main.hs
1 {-|
2 Module : Main.hs
3 Description : Gargantext starter
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Script to start gargantext with different modes (Dev, Prod, Mock).
11
12 -}
13
14 {-# LANGUAGE DataKinds #-}
15 {-# LANGUAGE DeriveGeneric #-}
16 {-# LANGUAGE FlexibleInstances #-}
17 {-# LANGUAGE NoImplicitPrelude #-}
18 {-# LANGUAGE OverloadedStrings #-}
19 {-# LANGUAGE StandaloneDeriving #-}
20 {-# LANGUAGE TypeOperators #-}
21 {-# LANGUAGE Strict #-}
22
23 module Main where
24
25 import Data.Version (showVersion)
26 import Data.Text (unpack)
27 import qualified Paths_gargantext as PG -- cabal magic build module
28 import Options.Generic
29 import System.Exit (exitSuccess)
30
31 import Gargantext.Prelude
32 import Gargantext.API (startGargantext, Mode(..)) -- , startGargantextMock)
33
34 --------------------------------------------------------
35 -- Graph Tests
36 --import qualified Gargantext.Graph.Utils as U
37 --import qualified Gargantext.Graph.Distances.Conditional as C
38 --import qualified Gargantext.Graph.Distances.Distributional as D
39 --import qualified Gargantext.Graph.Distances.Matrice as M
40 --------------------------------------------------------
41
42 instance ParseRecord Mode
43 instance ParseField Mode
44 instance ParseFields Mode
45
46 data MyOptions w =
47 MyOptions { run :: w ::: Mode
48 <?> "Possible modes: Dev | Mock | Prod"
49 , port :: w ::: Maybe Int
50 <?> "By default: 8008"
51 , ini :: w ::: Maybe Text
52 <?> "Ini-file path of gargantext.ini"
53 , version :: w ::: Bool
54 <?> "Show version number and exit"
55 }
56 deriving (Generic)
57
58 instance ParseRecord (MyOptions Wrapped)
59 deriving instance Show (MyOptions Unwrapped)
60
61
62 main :: IO ()
63 main = do
64 MyOptions myMode myPort myIniFile myVersion <- unwrapRecord
65 "Gargantext server"
66
67 if myVersion then do
68 putStrLn $ "Version: " <> showVersion PG.version
69 System.Exit.exitSuccess
70 else
71 return ()
72
73 let myPort' = case myPort of
74 Just p -> p
75 Nothing -> 8008
76
77 let start = case myMode of
78 Mock -> panic "[ERROR] Mock mode unsupported"
79 _ -> startGargantext myMode myPort' (unpack myIniFile')
80 where
81 myIniFile' = case myIniFile of
82 Nothing -> panic "[ERROR] gargantext.ini needed"
83 Just i -> i
84
85 putStrLn $ "Starting with " <> show myMode <> " mode."
86 start
87