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
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
14
Merge Requests
14
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
gargantext
haskell-gargantext
Commits
520c7701
Commit
520c7701
authored
Jul 23, 2024
by
Alexandre Delanoë
1
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/adinapoli/issue-374' into dev
parents
ec845b10
9378fb7e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
31 deletions
+56
-31
ReverseProxy.hs
src/Gargantext/MicroServices/ReverseProxy.hs
+56
-31
No files found.
src/Gargantext/MicroServices/ReverseProxy.hs
View file @
520c7701
...
...
@@ -37,7 +37,6 @@ import Gargantext.API.Admin.Settings.MicroServices
import
Gargantext.API.Admin.Types
import
Gargantext.API.Routes.Named.Private
import
Gargantext.API.ThrowAll
(
throwAllRoutes
)
import
Gargantext.API.Types
(
HTML
)
import
Gargantext.Core.Config
(
gc_frame_write_url
)
import
Gargantext.Database.Prelude
(
hasConfig
)
import
Gargantext.Prelude
hiding
(
Handler
)
...
...
@@ -53,7 +52,6 @@ import Servant.Client.Core.BaseUrl
import
Servant.Server.Generic
import
Text.RE.Replace
hiding
(
Capture
)
import
Text.RE.TDFA.ByteString
import
Text.RawString.QQ
(
r
)
-- See https://github.com/haskell-servant/servant/issues/1601#issue-1338013029
instance
{-# OVERLAPPING #-}
...
...
@@ -124,7 +122,7 @@ data NotesProxy mode = NotesProxy
-- | The config file which contains the server settings for the websocket connection
-- that we have to overwrite with our settings.
,
configFile
::
mode
:-
"config"
:>
Get
'[
H
TML
]
T
.
Text
,
configFile
::
mode
:-
"config"
:>
Raw
-- | Once the connection has been established, this is the websocket endpoint to
-- poll edits.
...
...
@@ -164,29 +162,46 @@ server env = ReverseProxyAPI {
,
proxyPassAll
=
proxyPassServer
ST_notes
env
}
-- |
A customised
configuration file that the \"notes\" service would otherwise send us, that
-- |
Customise the
configuration file that the \"notes\" service would otherwise send us, that
-- overrides the 'urlpath' to contain the proper service path, so that the websocket connection
-- can be started correctly. If we do not override the 'urlpath', due to the way things work
-- internally, the Javascript of CodiMD would otherwise take the first slice of the URL path
-- (something like `/notes/<frameId>`) and use /that/ as the <frameId>, which would be wrong
-- as it would try to establish a connection to `noteId=notes`.
configJS
::
BaseUrl
->
ServiceType
->
T
.
Text
configJS
bu
st
=
T
.
pack
$
[
r
|
window.domain = '
|]
<>
(
baseUrlHost
bu
)
<>
[
r
|
'
window.urlpath = '
|]
<>
renderServiceType
st
<>
[
r
|
'
window.debug = false
window.version = '1.2.0'
customiseConfigJS
::
BaseUrl
->
ServiceType
->
ConduitT
B
.
ByteString
(
Flush
Builder
)
IO
()
customiseConfigJS
bu
st
=
CC
.
map
flushReplace
where
-- Replaces the relative links in the proxied page content with proper urls.
flushReplace
::
B
.
ByteString
->
Flush
Builder
flushReplace
=
Chunk
.
byteString
.
replaceWindowDomain
.
replaceUrlPath
replaceWindowDomain
::
B
.
ByteString
->
B
.
ByteString
replaceWindowDomain
htmlBlob
=
replaceAllCaptures
ALL
makeAbsolute
$
htmlBlob
*=~
[
re
|
window.domain.*=*'.*'$
|]
where
makeAbsolute
_
_loc
cap
=
case
capturedText
cap
of
_
->
Just
$
C8
.
pack
$
"window.domain = '"
<>
(
baseUrlHost
bu
)
<>
"'"
window.allowedUploadMimeTypes = ["image/jpeg","image/png","image/jpg","image/gif","image/svg+xml"]
replaceUrlPath
::
B
.
ByteString
->
B
.
ByteString
replaceUrlPath
htmlBlob
=
replaceAllCaptures
ALL
makeAbsolute
$
htmlBlob
*=~
[
re
|
window.urlpath.*=*'.*'$
|]
where
makeAbsolute
_
_loc
cap
=
case
capturedText
cap
of
_
->
Just
$
C8
.
pack
$
"window.urlpath = '"
<>
renderServiceType
st
<>
"'"
window.DROPBOX_APP_KEY = ''
|]
configFileSettings
::
Env
->
ServiceType
->
WaiProxySettings
configFileSettings
env
sty
=
defaultWaiProxySettings
{
wpsProcessBody
=
\
_req
_res
->
Just
$
customiseConfigJS
(
proxyUrl
env
)
sty
}
notesProxyImplementation
::
Env
->
NotesProxy
AsServer
notesProxyImplementation
env
=
NotesProxy
{
slideEp
=
\
frameId
->
slideProxyServer
env
frameId
,
publishEp
=
\
frameId
->
publishProxyServer
env
frameId
,
configFile
=
pure
$
configJS
(
proxyUrl
env
)
sty
,
configFile
=
defaultForwardServerWithSettings
sty
id
env
(
configFileSettings
env
sty
)
,
notesSocket
=
socketIOProxyImplementation
sty
env
,
meEndpoint
=
proxyPassServer
sty
env
,
notesEp
=
\
_frameId
->
defaultForwardServer
sty
id
env
...
...
@@ -250,12 +265,12 @@ removeFromReferer pth originalRequest =
proxyUrl
::
Env
->
BaseUrl
proxyUrl
env
=
mkProxyUrl
(
env
^.
hasConfig
)
(
env
^.
env_settings
.
microservicesSettings
)
defaultForwardServer
::
ServiceType
->
(
Request
->
Request
)
->
Env
->
ServerT
Raw
m
defaultForwardServer
sty
presendModifyRequest
env
=
defaultForwardServerWithSettings
::
ServiceType
->
(
Request
->
Request
)
->
Env
->
WaiProxySettings
->
ServerT
Raw
m
defaultForwardServer
WithSettings
sty
presendModifyRequest
env
proxySettings
=
Tagged
$
waiProxyToSettings
forwardRequest
(
proxySettings
)
(
env
^.
env_manager
)
where
...
...
@@ -265,17 +280,6 @@ defaultForwardServer sty presendModifyRequest env =
proxyUrlStr
::
String
proxyUrlStr
=
showBaseUrl
(
proxyUrl
env
)
proxySettings
::
WaiProxySettings
proxySettings
=
defaultWaiProxySettings
{
wpsProcessBody
=
\
_req
_res
->
Just
$
replaceRelativeLinks
microURL
proxyPath
,
wpsModifyResponseHeaders
=
\
_req
_res
->
tweakResponseHeaders
,
wpsRedirectCounts
=
5
}
where
microURL
=
proxyDestination
proxyPath
=
C8
.
pack
$
proxyUrlStr
<>
serviceTypeToProxyPath
sty
setHost
::
ProxyDestination
->
RequestHeaders
->
RequestHeaders
setHost
hst
hdrs
=
(
hHost
,
fwdHost
hst
)
:
filter
((
/=
)
hHost
.
fst
)
hdrs
...
...
@@ -292,6 +296,27 @@ defaultForwardServer sty presendModifyRequest env =
}
pure
$
WPRModifiedRequest
proxiedReq
(
ProxyDest
(
fwdHost
proxyDestination
)
(
fwdPort
proxyDestination
))
defaultForwardServer
::
ServiceType
->
(
Request
->
Request
)
->
Env
->
ServerT
Raw
m
defaultForwardServer
sty
presendModifyRequest
env
=
defaultForwardServerWithSettings
sty
presendModifyRequest
env
$
defaultWaiProxySettings
{
wpsProcessBody
=
\
_req
_res
->
Just
$
replaceRelativeLinks
proxyDestination
proxyPath
,
wpsModifyResponseHeaders
=
\
_req
_res
->
tweakResponseHeaders
,
wpsRedirectCounts
=
5
}
where
proxyPath
=
C8
.
pack
$
proxyUrlStr
<>
serviceTypeToProxyPath
sty
proxyDestination
::
ProxyDestination
proxyDestination
=
mkProxyDestination
env
proxyUrlStr
::
String
proxyUrlStr
=
showBaseUrl
(
proxyUrl
env
)
--
-- Utility functions
--
...
...
Przemyslaw Kaminski
@cgenie
mentioned in commit
5660aec0
·
Oct 08, 2024
mentioned in commit
5660aec0
mentioned in commit 5660aec07ec5a0a0a5468f440092c1a8f57a864e
Toggle commit list
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