]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-server/Main.hs
[API Query] api connection ok, needs RootId fix
[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) -- , 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 data Mode = Dev | Mock | Prod
43 deriving (Show, Read, Generic)
44 instance ParseRecord Mode
45 instance ParseField Mode
46 instance ParseFields Mode
47
48
49 data MyOptions w =
50 MyOptions { run :: w ::: Mode
51 <?> "Possible modes: Dev | Mock | Prod"
52 , port :: w ::: Maybe Int
53 <?> "By default: 8008"
54 , ini :: w ::: Maybe Text
55 <?> "Ini-file path of gargantext.ini"
56 , version :: w ::: Bool
57 <?> "Show version number and exit"
58 }
59 deriving (Generic)
60
61 instance ParseRecord (MyOptions Wrapped)
62 deriving instance Show (MyOptions Unwrapped)
63
64
65 main :: IO ()
66 main = do
67 MyOptions myMode myPort myIniFile myVersion <- unwrapRecord
68 "Gargantext server"
69
70 if myVersion then do
71 putStrLn $ "Version: " <> showVersion PG.version
72 System.Exit.exitSuccess
73 else
74 return ()
75
76 let myPort' = case myPort of
77 Just p -> p
78 Nothing -> 8008
79
80 let start = case myMode of
81 Prod -> startGargantext myPort' (unpack myIniFile')
82 where
83 myIniFile' = case myIniFile of
84 Nothing -> panic "[ERROR] gargantext.ini needed"
85 Just i -> i
86 Dev -> panic "[ERROR] Dev mode unsupported"
87 Mock -> panic "[ERROR] Mock mode unsupported"
88 -- _ -> startGargantextMock myPort'
89
90 putStrLn $ "Starting with " <> show myMode <> " mode."
91 start
92