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
Christian Merten
haskell-gargantext
Commits
37545535
Commit
37545535
authored
Jul 17, 2024
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/adinapoli/issue-370' into dev
parents
6d63b50c
a8dcfe1a
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
19 deletions
+39
-19
update-project-dependencies
bin/update-project-dependencies
+1
-1
cabal.project.freeze
cabal.project.freeze
+2
-0
gargantext-settings.toml
gargantext-settings.toml
+1
-0
gargantext.cabal
gargantext.cabal
+1
-0
API.hs
src/Gargantext/API.hs
+4
-2
CORS.hs
src/Gargantext/API/Admin/Settings/CORS.hs
+7
-4
TOML.hs
src/Gargantext/API/Admin/Settings/TOML.hs
+5
-5
ReverseProxy.hs
src/Gargantext/MicroServices/ReverseProxy.hs
+15
-7
stack.yaml
stack.yaml
+3
-0
No files found.
bin/update-project-dependencies
View file @
37545535
...
@@ -19,7 +19,7 @@ fi
...
@@ -19,7 +19,7 @@ fi
# `cabal.project.freeze`. This ensures the files stay deterministic so that CI
# `cabal.project.freeze`. This ensures the files stay deterministic so that CI
# cache can kick in.
# cache can kick in.
expected_cabal_project_hash
=
"ec368714e0d4213dcc60e7c98344ab9a4ecbcff522deb4c57a12490e3b048585"
expected_cabal_project_hash
=
"ec368714e0d4213dcc60e7c98344ab9a4ecbcff522deb4c57a12490e3b048585"
expected_cabal_project_freeze_hash
=
"
ca1592c985ffead024c6635eb39b293e2525a547fe93293fdee9ce1148083f22
"
expected_cabal_project_freeze_hash
=
"
0999af7642e822e6b4e2996b743c8f924cdfa406c9b2941bb53f1ca7b3a0737d
"
cabal
--store-dir
=
$STORE_DIR
v2-build
--dry-run
cabal
--store-dir
=
$STORE_DIR
v2-build
--dry-run
cabal2stack
--system-ghc
--allow-newer
--resolver
lts-21.17
--resolver-file
devops/stack/lts-21.17.yaml
-o
stack.yaml
cabal2stack
--system-ghc
--allow-newer
--resolver
lts-21.17
--resolver-file
devops/stack/lts-21.17.yaml
-o
stack.yaml
...
...
cabal.project.freeze
View file @
37545535
...
@@ -545,6 +545,8 @@ constraints: any.Cabal ==3.8.1.0,
...
@@ -545,6 +545,8 @@ constraints: any.Cabal ==3.8.1.0,
streaming-commons -use-bytestring-builder,
streaming-commons -use-bytestring-builder,
any.strict ==0.5,
any.strict ==0.5,
any.string-conversions ==0.4.0.1,
any.string-conversions ==0.4.0.1,
any.stringsearch ==0.3.6.6,
stringsearch -base3 +base4,
any.swagger2 ==2.8.7,
any.swagger2 ==2.8.7,
any.syb ==0.7.2.4,
any.syb ==0.7.2.4,
any.system-cxx-std-lib ==1.0,
any.system-cxx-std-lib ==1.0,
...
...
gargantext-settings.toml
View file @
37545535
...
@@ -15,6 +15,7 @@ allowed-origins = [
...
@@ -15,6 +15,7 @@ allowed-origins = [
,
"https://msh.sub.gargantext.org"
,
"https://msh.sub.gargantext.org"
,
"https://dev.sub.gargantext.org"
,
"https://dev.sub.gargantext.org"
,
"http://localhost:8008"
,
"http://localhost:8008"
,
"http://localhost:3000"
]
]
use-origins-for-hosts
=
true
use-origins-for-hosts
=
true
...
...
gargantext.cabal
View file @
37545535
...
@@ -662,6 +662,7 @@ library
...
@@ -662,6 +662,7 @@ library
, split ^>= 0.2.3.4
, split ^>= 0.2.3.4
, stemmer ^>= 0.5.2
, stemmer ^>= 0.5.2
, stm ^>= 2.5.0.1
, stm ^>= 2.5.0.1
, stringsearch >= 0.3.6.6
, swagger2 ^>= 2.6
, swagger2 ^>= 2.6
, taggy-lens ^>= 0.1.2
, taggy-lens ^>= 0.1.2
, tagsoup ^>= 0.14.8
, tagsoup ^>= 0.14.8
...
...
src/Gargantext/API.hs
View file @
37545535
...
@@ -38,6 +38,7 @@ import Control.Concurrent
...
@@ -38,6 +38,7 @@ import Control.Concurrent
import
Control.Concurrent.Async
qualified
as
Async
import
Control.Concurrent.Async
qualified
as
Async
import
Control.Lens
hiding
(
Level
)
import
Control.Lens
hiding
(
Level
)
import
Data.List
(
lookup
)
import
Data.List
(
lookup
)
import
Data.Set
qualified
as
Set
import
Data.Text
(
pack
)
import
Data.Text
(
pack
)
import
Data.Text.Encoding
qualified
as
TE
import
Data.Text.Encoding
qualified
as
TE
import
Data.Text.IO
(
putStrLn
)
import
Data.Text.IO
(
putStrLn
)
...
@@ -64,6 +65,7 @@ import Network.Wai.Middleware.Cors
...
@@ -64,6 +65,7 @@ import Network.Wai.Middleware.Cors
import
Network.Wai.Middleware.RequestLogger
import
Network.Wai.Middleware.RequestLogger
import
Paths_gargantext
(
getDataDir
)
import
Paths_gargantext
(
getDataDir
)
import
Servant
hiding
(
Header
)
import
Servant
hiding
(
Header
)
import
Servant.Client.Core.BaseUrl
(
showBaseUrl
)
import
System.Cron.Schedule
qualified
as
Cron
import
System.Cron.Schedule
qualified
as
Cron
import
System.FilePath
import
System.FilePath
...
@@ -154,7 +156,7 @@ makeGargMiddleware :: CORSSettings -> Mode -> IO Middleware
...
@@ -154,7 +156,7 @@ makeGargMiddleware :: CORSSettings -> Mode -> IO Middleware
makeGargMiddleware
crsSettings
mode
=
do
makeGargMiddleware
crsSettings
mode
=
do
let
corsMiddleware
=
cors
$
\
_incomingRq
->
Just
let
corsMiddleware
=
cors
$
\
_incomingRq
->
Just
simpleCorsResourcePolicy
simpleCorsResourcePolicy
{
corsOrigins
=
Just
(
map
mkCorsOrigin
(
crsSettings
^.
corsAllowedOrigins
),
True
)
{
corsOrigins
=
Just
$
(
Set
.
toList
$
Set
.
fromList
$
map
mkCorsOrigin
(
crsSettings
^.
corsAllowedOrigins
),
True
)
,
corsMethods
=
[
methodGet
,
methodPost
,
methodPut
,
corsMethods
=
[
methodGet
,
methodPost
,
methodPut
,
methodDelete
,
methodOptions
,
methodHead
]
,
methodDelete
,
methodOptions
,
methodHead
]
,
corsIgnoreFailures
=
False
,
corsIgnoreFailures
=
False
...
@@ -168,7 +170,7 @@ makeGargMiddleware crsSettings mode = do
...
@@ -168,7 +170,7 @@ makeGargMiddleware crsSettings mode = do
pure
$
loggerMiddleware
.
corsMiddleware
pure
$
loggerMiddleware
.
corsMiddleware
where
where
mkCorsOrigin
::
CORSOrigin
->
Origin
mkCorsOrigin
::
CORSOrigin
->
Origin
mkCorsOrigin
=
TE
.
encodeUtf8
.
_CORSOrigin
mkCorsOrigin
(
CORSOrigin
u
)
=
TE
.
encodeUtf8
.
pack
.
showBaseUrl
$
u
---------------------------------------------------------------------
---------------------------------------------------------------------
-- | API Global
-- | API Global
...
...
src/Gargantext/API/Admin/Settings/CORS.hs
View file @
37545535
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
module
Gargantext.API.Admin.Settings.CORS
where
module
Gargantext.API.Admin.Settings.CORS
where
import
Prelude
import
Prelude
...
@@ -10,10 +11,11 @@ import Control.Arrow
...
@@ -10,10 +11,11 @@ import Control.Arrow
import
Data.Text
qualified
as
T
import
Data.Text
qualified
as
T
import
Toml
import
Toml
import
Control.Lens
hiding
(
iso
,
(
.=
))
import
Control.Lens
hiding
(
iso
,
(
.=
))
import
Data.String
(
IsString
)
import
Servant.Client.Core
import
Data.Maybe
(
fromMaybe
)
newtype
CORSOrigin
=
CORSOrigin
{
_CORSOrigin
::
T
.
Text
}
newtype
CORSOrigin
=
CORSOrigin
{
_CORSOrigin
::
BaseUrl
}
deriving
(
Show
,
Eq
,
IsString
)
deriving
(
Show
,
Eq
)
data
CORSSettings
=
data
CORSSettings
=
CORSSettings
{
CORSSettings
{
...
@@ -30,7 +32,8 @@ corsOriginCodec :: TomlBiMap CORSOrigin AnyValue
...
@@ -30,7 +32,8 @@ corsOriginCodec :: TomlBiMap CORSOrigin AnyValue
corsOriginCodec
=
_Orig
>>>
_Text
corsOriginCodec
=
_Orig
>>>
_Text
where
where
_Orig
::
BiMap
e
CORSOrigin
T
.
Text
_Orig
::
BiMap
e
CORSOrigin
T
.
Text
_Orig
=
iso
_CORSOrigin
CORSOrigin
_Orig
=
iso
(
T
.
pack
.
showBaseUrl
.
_CORSOrigin
)
(
\
(
T
.
unpack
->
u
)
->
CORSOrigin
.
fromMaybe
(
error
$
"invalid origin: "
<>
u
)
.
parseBaseUrl
$
u
)
corsSettingsCodec
::
TomlCodec
CORSSettings
corsSettingsCodec
::
TomlCodec
CORSSettings
corsSettingsCodec
=
CORSSettings
corsSettingsCodec
=
CORSSettings
...
...
src/Gargantext/API/Admin/Settings/TOML.hs
View file @
37545535
...
@@ -33,9 +33,7 @@ addProxyToAllowedOrigins stgs =
...
@@ -33,9 +33,7 @@ addProxyToAllowedOrigins stgs =
addProxies
::
Int
->
CORSSettings
->
CORSSettings
addProxies
::
Int
->
CORSSettings
->
CORSSettings
addProxies
port
cors
=
addProxies
port
cors
=
let
origins
=
_corsAllowedOrigins
cors
let
origins
=
_corsAllowedOrigins
cors
mkUrl
(
CORSOrigin
u
)
=
case
parseBaseUrl
(
T
.
unpack
u
)
of
mkUrl
(
CORSOrigin
bh
)
=
CORSOrigin
$
bh
{
baseUrlPort
=
port
}
Nothing
->
CORSOrigin
u
Just
bh
->
CORSOrigin
$
T
.
pack
$
showBaseUrl
$
bh
{
baseUrlPort
=
port
}
in
cors
{
_corsAllowedOrigins
=
origins
<>
Prelude
.
map
mkUrl
origins
}
in
cors
{
_corsAllowedOrigins
=
origins
<>
Prelude
.
map
mkUrl
origins
}
-- | Loads the 'CORSSettings' from the 'toml' file.
-- | Loads the 'CORSSettings' from the 'toml' file.
...
@@ -48,5 +46,7 @@ loadGargTomlSettings tomlFile = do
...
@@ -48,5 +46,7 @@ loadGargTomlSettings tomlFile = do
logMsg
ioLogger
ERROR
$
T
.
unpack
$
"Error, gargantext-settings.toml parsing failed: "
<>
Toml
.
prettyTomlDecodeErrors
errs
logMsg
ioLogger
ERROR
$
T
.
unpack
$
"Error, gargantext-settings.toml parsing failed: "
<>
Toml
.
prettyTomlDecodeErrors
errs
panicTrace
"Please fix the errors in your gargantext-settings.toml file."
panicTrace
"Please fix the errors in your gargantext-settings.toml file."
Right
settings0
->
case
settings0
^.
gargCorsSettings
.
corsUseOriginsForHosts
of
Right
settings0
->
case
settings0
^.
gargCorsSettings
.
corsUseOriginsForHosts
of
True
->
pure
$
addProxyToAllowedOrigins
$
settings0
&
over
(
gargCorsSettings
.
corsAllowedHosts
)
(
\
_
->
"http://localhost:3000"
:
(
settings0
^.
gargCorsSettings
.
corsAllowedOrigins
))
True
->
pure
$
addProxyToAllowedOrigins
$
False
->
pure
$
addProxyToAllowedOrigins
$
settings0
&
over
(
gargCorsSettings
.
corsAllowedHosts
)
(
"http://localhost:3000"
:
)
settings0
&
over
(
gargCorsSettings
.
corsAllowedHosts
)
(
\
_
->
(
settings0
^.
gargCorsSettings
.
corsAllowedOrigins
))
False
->
pure
$
addProxyToAllowedOrigins
settings0
src/Gargantext/MicroServices/ReverseProxy.hs
View file @
37545535
...
@@ -24,11 +24,14 @@ import Conduit
...
@@ -24,11 +24,14 @@ import Conduit
import
Data.ByteString
qualified
as
B
import
Data.ByteString
qualified
as
B
import
Data.ByteString.Builder
import
Data.ByteString.Builder
import
Data.ByteString.Char8
qualified
as
C8
import
Data.ByteString.Char8
qualified
as
C8
import
Data.ByteString.Lazy
qualified
as
BL
import
Data.ByteString.Search
qualified
as
BS
import
Data.Conduit.List
qualified
as
CC
import
Data.Conduit.List
qualified
as
CC
import
Data.String
import
Data.String
import
Data.Text
qualified
as
T
import
Data.Text
qualified
as
T
import
Data.Text.Encoding
qualified
as
TE
import
Data.Text.Encoding
qualified
as
TE
import
GHC.Generics
import
GHC.Generics
import
Gargantext.API.Admin.Auth.Types
(
AuthContext
)
import
Gargantext.API.Admin.EnvTypes
import
Gargantext.API.Admin.EnvTypes
import
Gargantext.API.Admin.Settings.MicroServices
import
Gargantext.API.Admin.Settings.MicroServices
import
Gargantext.API.Admin.Types
import
Gargantext.API.Admin.Types
...
@@ -41,17 +44,16 @@ import Gargantext.Prelude hiding (Handler)
...
@@ -41,17 +44,16 @@ import Gargantext.Prelude hiding (Handler)
import
Network.HTTP.ReverseProxy
import
Network.HTTP.ReverseProxy
import
Network.HTTP.Types
(
hCacheControl
,
RequestHeaders
,
hReferer
,
ResponseHeaders
,
Header
)
import
Network.HTTP.Types
(
hCacheControl
,
RequestHeaders
,
hReferer
,
ResponseHeaders
,
Header
)
import
Network.HTTP.Types.Header
(
hHost
)
import
Network.HTTP.Types.Header
(
hHost
)
import
Network.Wai
import
Servant
hiding
(
Header
)
import
Servant
hiding
(
Header
)
import
Servant.Auth.Server
import
Servant.Auth.Server
import
Servant.Auth.Server.Internal.AddSetCookie
import
Servant.Auth.Swagger
()
import
Servant.Auth.Swagger
()
import
Servant.Client.Core.BaseUrl
import
Servant.Client.Core.BaseUrl
import
Servant.Server.Generic
import
Servant.Server.Generic
import
Text.RE.Replace
hiding
(
Capture
)
import
Text.RE.Replace
hiding
(
Capture
)
import
Text.RE.TDFA.ByteString
import
Text.RE.TDFA.ByteString
import
Text.RawString.QQ
(
r
)
import
Text.RawString.QQ
(
r
)
import
Gargantext.API.Admin.Auth.Types
(
AuthContext
)
import
Servant.Auth.Server.Internal.AddSetCookie
import
Network.Wai
-- See https://github.com/haskell-servant/servant/issues/1601#issue-1338013029
-- See https://github.com/haskell-servant/servant/issues/1601#issue-1338013029
instance
{-# OVERLAPPING #-}
instance
{-# OVERLAPPING #-}
...
@@ -266,10 +268,13 @@ defaultForwardServer sty presendModifyRequest env =
...
@@ -266,10 +268,13 @@ defaultForwardServer sty presendModifyRequest env =
proxySettings
::
WaiProxySettings
proxySettings
::
WaiProxySettings
proxySettings
=
proxySettings
=
defaultWaiProxySettings
{
defaultWaiProxySettings
{
wpsProcessBody
=
\
_req
_res
->
Just
$
replaceRelativeLinks
(
C8
.
pack
$
proxyUrlStr
<>
serviceTypeToProxyPath
sty
)
wpsProcessBody
=
\
_req
_res
->
Just
$
replaceRelativeLinks
microURL
proxyPath
,
wpsModifyResponseHeaders
=
\
_req
_res
->
tweakResponseHeaders
,
wpsModifyResponseHeaders
=
\
_req
_res
->
tweakResponseHeaders
,
wpsRedirectCounts
=
5
,
wpsRedirectCounts
=
5
}
}
where
microURL
=
proxyDestination
proxyPath
=
C8
.
pack
$
proxyUrlStr
<>
serviceTypeToProxyPath
sty
setHost
::
ProxyDestination
->
RequestHeaders
->
RequestHeaders
setHost
::
ProxyDestination
->
RequestHeaders
->
RequestHeaders
setHost
hst
hdrs
=
(
hHost
,
fwdHost
hst
)
:
filter
((
/=
)
hHost
.
fst
)
hdrs
setHost
hst
hdrs
=
(
hHost
,
fwdHost
hst
)
:
filter
((
/=
)
hHost
.
fst
)
hdrs
...
@@ -306,12 +311,15 @@ tweakResponseHeaders = Prelude.map tweakHeader
...
@@ -306,12 +311,15 @@ tweakResponseHeaders = Prelude.map tweakHeader
=
(
k
,
v
)
=
(
k
,
v
)
-- | Replaces the relative links in any HTML blob returned by the proxy.
-- | Replaces the relative links in any HTML blob returned by the proxy.
replaceRelativeLinks
::
B
.
ByteString
->
ConduitT
B
.
ByteString
(
Flush
Builder
)
IO
()
replaceRelativeLinks
::
ProxyDestination
->
B
.
ByteString
->
ConduitT
B
.
ByteString
(
Flush
Builder
)
IO
()
replaceRelativeLinks
assetPath
=
CC
.
map
flushReplace
replaceRelativeLinks
proxyTarget
assetPath
=
CC
.
map
flushReplace
where
where
-- Replaces the relative links in the proxied page content with proper urls.
-- Replaces the relative links in the proxied page content with proper urls.
flushReplace
::
B
.
ByteString
->
Flush
Builder
flushReplace
::
B
.
ByteString
->
Flush
Builder
flushReplace
=
Chunk
.
byteString
.
replaceIt
flushReplace
=
Chunk
.
byteString
.
BL
.
toStrict
.
BS
.
replace
(
C8
.
pack
.
showBaseUrl
.
_ProxyDestination
$
proxyTarget
)
assetPath
.
replaceIt
replaceIt
::
B
.
ByteString
->
B
.
ByteString
replaceIt
::
B
.
ByteString
->
B
.
ByteString
replaceIt
htmlBlob
=
replaceIt
htmlBlob
=
...
...
stack.yaml
View file @
37545535
...
@@ -513,6 +513,9 @@ flags:
...
@@ -513,6 +513,9 @@ flags:
"
optimised-mixer"
:
false
"
optimised-mixer"
:
false
"
streaming-commons"
:
"
streaming-commons"
:
"
use-bytestring-builder"
:
false
"
use-bytestring-builder"
:
false
stringsearch
:
base3
:
false
base4
:
true
tagged
:
tagged
:
deepseq
:
true
deepseq
:
true
transformers
:
true
transformers
:
true
...
...
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