Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
haskell-gargantext
Commits
0ef1cb1d
Verified
Commit
0ef1cb1d
authored
Feb 26, 2024
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[server] some refactoring
parent
9f30d0b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
22 deletions
+16
-22
Main.hs
bin/gargantext-server/Main.hs
+4
-6
API.hs
src/Gargantext/API.hs
+12
-16
No files found.
bin/gargantext-server/Main.hs
View file @
0ef1cb1d
...
...
@@ -11,7 +11,6 @@ Script to start gargantext with different modes (Dev, Prod, Mock).
-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TypeOperators #-}
...
...
@@ -22,16 +21,17 @@ Script to start gargantext with different modes (Dev, Prod, Mock).
module
Main
where
import
Data.Maybe
(
fromMaybe
)
import
Data.Text
(
unpack
)
import
Data.Version
(
showVersion
)
import
GHC.IO.Encoding
import
Gargantext.API
(
startGargantext
)
-- , startGargantextMock)
import
Gargantext.API.Admin.EnvTypes
import
Gargantext.Prelude
import
Gargantext.System.Logging
import
GHC.IO.Encoding
import
Options.Generic
import
Paths_gargantext
qualified
as
PG
-- cabal magic build module
import
System.Exit
(
exitSuccess
)
import
qualified
Paths_gargantext
as
PG
-- cabal magic build module
instance
ParseRecord
Mode
...
...
@@ -69,9 +69,7 @@ main = withLogger () $ \ioLogger -> do
else
return
()
---------------------------------------------------------------
let
myPort'
=
case
myPort
of
Just
p
->
p
Nothing
->
8008
let
myPort'
=
fromMaybe
8008
myPort
myIniFile'
=
case
myIniFile
of
Nothing
->
panicTrace
"[ERROR] gargantext.ini needed"
...
...
src/Gargantext/API.hs
View file @
0ef1cb1d
...
...
@@ -27,41 +27,37 @@ Pouillard (who mainly made it).
-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module
Gargantext.API
where
import
Control.Concurrent
import
Control.Lens
hiding
(
Level
)
import
Data.List
(
lookup
)
import
Data.Text
(
pack
)
import
Data.Text.Encoding
qualified
as
TE
import
Data.Text.IO
(
putStrLn
)
import
Data.Validity
import
Gargantext.API.Admin.Auth.Types
(
AuthContext
)
import
Gargantext.API.Admin.EnvTypes
(
Env
,
Mode
(
..
))
import
Gargantext.API.Admin.Settings
(
newEnv
)
import
Gargantext.API.Admin.Settings.CORS
import
Gargantext.API.Admin.Settings.CORS
(
corsAllowedOrigins
,
CORSOrigin
(
_CORSOrigin
),
CORSSettings
)
import
Gargantext.API.Admin.Types
(
FireWall
(
..
),
PortNumber
,
cookieSettings
,
jwtSettings
,
settings
,
corsSettings
)
import
Gargantext.API.EKG
import
Gargantext.API.EKG
(
ekgServer
,
newEkgStore
,
EkgAPI
)
import
Gargantext.API.Middleware
(
logStdoutDevSanitised
)
import
Gargantext.API.Routes
import
Gargantext.API.Routes
(
API
,
GargAPI
)
import
Gargantext.API.Server
(
server
)
import
Gargantext.Database.Prelude
qualified
as
DB
import
Gargantext.Prelude
hiding
(
putStrLn
)
import
Gargantext.System.Logging
import
Network.HTTP.Types
hiding
(
Query
)
import
Network.Wai
import
Network.Wai.Handler.Warp
hiding
(
defaultSettings
)
import
Gargantext.System.Logging
(
withLoggerHoisted
)
import
Network.HTTP.Types
(
methodDelete
,
methodGet
,
methodHead
,
methodOptions
,
methodPost
,
methodPut
)
import
Network.Wai
(
Middleware
,
Request
(
requestHeaders
)
)
import
Network.Wai.Handler.Warp
(
run
)
import
Network.Wai.Middleware.Cors
import
Network.Wai.Middleware.RequestLogger
import
Network.Wai.Middleware.RequestLogger
(
logStdout
)
import
Paths_gargantext
(
getDataDir
)
import
Servant
hiding
(
Header
)
import
System.Cron.Schedule
qualified
as
Cron
import
System.FilePath
import
System.FilePath
(
(
</>
)
)
-- | startGargantext takes as parameters port number and Ini file.
startGargantext
::
Mode
->
PortNumber
->
FilePath
->
IO
()
...
...
@@ -79,7 +75,7 @@ startGargantext mode port file = withLoggerHoisted mode $ \logger -> do
(
\
(
_
::
SomeException
)
->
pure
$
Right
False
)
case
r
of
Right
True
->
pure
()
_
->
panicTrace
$
_
left
->
panicTrace
$
"You must run 'gargantext-init "
<>
pack
file
<>
"' before running gargantext-server (only the first time)."
...
...
@@ -131,7 +127,7 @@ fireWall req fw = do
if
origin
==
Just
(
encodeUtf8
"http://localhost:8008"
)
&&
host
==
Just
(
encodeUtf8
"localhost:3000"
)
||
(
not
$
unFireWall
fw
)
||
not
(
unFireWall
fw
)
then
pure
True
else
pure
False
...
...
@@ -149,7 +145,7 @@ makeGargMiddleware crsSettings mode = do
}
case
mode
of
Prod
->
pure
$
logStdout
.
corsMiddleware
_
->
do
_
otherwise
->
do
loggerMiddleware
<-
logStdoutDevSanitised
pure
$
loggerMiddleware
.
corsMiddleware
where
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment