Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Genesys Website
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
32
Issues
32
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Website
Commits
5a200cee
Commit
5a200cee
authored
Oct 22, 2020
by
Oleksii Savran
Committed by
Matija Obreza
Oct 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proxy upgrade
parent
eaac296f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
39 deletions
+75
-39
workspaces/ui-express/package.json
workspaces/ui-express/package.json
+2
-1
workspaces/ui-express/server/middleware/geonamesHttpProxy.ts
workspaces/ui-express/server/middleware/geonamesHttpProxy.ts
+10
-9
workspaces/ui-express/server/middleware/httpProxy.ts
workspaces/ui-express/server/middleware/httpProxy.ts
+58
-27
workspaces/ui-express/server/server.ts
workspaces/ui-express/server/server.ts
+5
-2
No files found.
workspaces/ui-express/package.json
View file @
5a200cee
...
...
@@ -58,11 +58,11 @@
"debug"
:
"^4.1.1"
,
"es-cookie"
:
"^1.3.2"
,
"express"
:
"^4.17.1"
,
"express-http-proxy"
:
"^1.6.0"
,
"fast-glob"
:
"^3.2.2"
,
"flattenjs"
:
"^2.0.0"
,
"form-data"
:
"^3.0.0"
,
"history"
:
"^4.10.1"
,
"http-proxy-middleware"
:
"^1.0.6"
,
"i18next"
:
"^19.4.0"
,
"i18next-browser-languagedetector"
:
"^4.0.2"
,
"i18next-express-middleware"
:
"^1.9.1"
,
...
...
@@ -76,6 +76,7 @@
"lodash"
:
"^4.17.19"
,
"minimist"
:
"^1.2.5"
,
"moment"
:
"^2.24.0"
,
"multer"
:
"^1.4.2"
,
"normalize.css"
:
"^8.0.1"
,
"prop-types"
:
"^15.7.2"
,
"query-string"
:
"^6.12.0"
,
...
...
workspaces/ui-express/server/middleware/geonamesHttpProxy.ts
View file @
5a200cee
import
*
as
proxy
from
'
express-http-proxy
'
;
import
{
createProxyMiddleware
}
from
'
http-proxy-middleware
'
;
import
config
from
'
../config
'
;
import
{
Request
}
from
'
express
'
;
const
geonamesApiUrl
=
'
https://secure.geonames.org
'
;
const
geonamesHttpProxy
=
proxy
(
geonamesApiUrl
,
{
parseReqBody
:
false
,
const
geonamesHttpProxy
=
createProxyMiddleware
(
{
target
:
geonamesApiUrl
,
proxyReqPathResolver
:
(
req
)
=>
{
const
path
=
`
${
req
.
url
}
&username=
${
config
.
geonamesUsername
}
`
;
pathRewrite
:
(
path
:
string
,
req
:
Request
)
=>
{
let
updatedPath
=
path
.
replace
(
'
/proxy/api/geonames
'
,
''
);
updatedPath
=
`
${
updatedPath
}
&username=
${
config
.
geonamesUsername
}
`
;
// remove all headers from request
req
.
headers
=
{};
console
.
log
(
`
HTTP proxy to
${
geonamesApiUrl
}${
path
}
`
);
return
path
;
delete
req
.
headers
;
console
.
log
(
`
HTTP proxy to
${
geonamesApiUrl
}${
updatedPath
}
`
);
return
updatedPath
;
},
});
...
...
workspaces/ui-express/server/middleware/httpProxy.ts
View file @
5a200cee
import
*
as
proxy
from
'
express-http-proxy
'
;
import
{
Request
,
Response
}
from
'
express
'
;
import
{
ClientRequest
}
from
'
http
'
;
import
FormData
from
'
form-data
'
;
import
{
forOwn
}
from
'
lodash
'
;
import
config
from
'
../config
'
;
import
refreshAuthToken
from
'
./refreshAuthToken
'
;
const
httpProxy
=
proxy
(
config
.
apiUrl
,
{
parseReqBody
:
false
,
timeout
:
config
.
apiTimeout
,
import
{
createProxyMiddleware
}
from
'
http-proxy-middleware
'
;
filter
:
(
req
,
res
)
=>
{
const
filter
=
(
path
:
string
,
req
:
Request
)
=>
{
if
(
req
.
url
.
startsWith
(
'
/oauth/
'
)
||
req
.
url
.
startsWith
(
'
/token
'
)
||
req
.
url
.
startsWith
(
'
/google
'
))
{
// console.log('Will proxy /oauth');
if
(
req
.
query
.
grant_type
===
'
refresh_token
'
&&
!
req
.
query
.
refresh_token
)
{
refreshAuthToken
(
req
,
res
);
return
true
;
}
console
.
log
(
'
Will proxy /oauth
'
);
return
true
;
}
// Not proxying the request
console
.
log
(
`
Not proxying
${
req
.
url
}
`
);
return
false
;
};
const
options
=
{
target
:
config
.
apiUrl
,
pathRewrite
:
(
path
:
string
,
req
:
Request
)
=>
{
// console.log('path', path);
let
updatedPath
=
path
.
replace
(
'
/proxy
'
,
''
);
if
(
updatedPath
.
startsWith
(
'
/google/verify-token
'
))
{
updatedPath
=
`
${
updatedPath
}
&clientId=
${
config
.
clientId
}
`
;
}
console
.
log
(
`
HTTP proxy to
${
config
.
apiUrl
}${
updatedPath
}
`
);
return
updatedPath
;
},
proxyReqPathResolver
:
(
req
)
=>
{
let
path
=
req
.
url
;
if
(
path
.
startsWith
(
'
/oauth/token
'
))
{
const
grantType
=
req
.
query
.
grant_type
;
if
(
grantType
===
'
client_credentials
'
||
grantType
===
'
password
'
||
grantType
===
'
refresh_token
'
)
{
path
=
`
${
path
}
&client_id=
${
config
.
clientId
}
&client_secret=
${
config
.
clientSecret
}
`
;
onProxyReq
(
proxyReq
:
ClientRequest
,
req
:
Request
,
res
:
Response
)
{
if
(
proxyReq
.
path
.
startsWith
(
'
/oauth/token
'
))
{
if
(
req
.
query
.
grant_type
===
'
refresh_token
'
&&
!
req
.
query
.
refresh_token
)
{
console
.
log
(
'
refreshAuthToken
'
);
refreshAuthToken
(
req
,
res
);
}
}
else
if
(
path
.
startsWith
(
'
/google/verify-token
'
))
{
path
=
`
${
path
}
&clientId=
${
config
.
clientId
}
`
;
const
form
=
new
FormData
();
forOwn
(
req
.
body
,
(
value
,
key
)
=>
{
if
(
key
!==
'
client_id
'
&&
key
!==
'
client_secret
'
)
{
form
.
append
(
key
,
value
);
}
});
form
.
append
(
'
client_id
'
,
config
.
clientId
);
form
.
append
(
'
client_secret
'
,
config
.
clientSecret
);
delete
req
.
body
;
console
.
log
(
`
HTTP proxy to
${
config
.
apiUrl
}${
path
}
`
);
return
path
;
const
headers
=
form
.
getHeaders
();
proxyReq
.
setHeader
(
'
Content-Type
'
,
headers
[
'
content-type
'
]);
proxyReq
.
setHeader
(
'
Content-Length
'
,
form
.
getLengthSync
());
// form.getLength((err, length) => { // requires socket.pause()?
// proxyReq.setHeader('Content-Length', length);
// form.pipe(proxyReq);
// });
form
.
pipe
(
proxyReq
);
}
},
});
};
// Proxy configuration
const
httpProxy
=
createProxyMiddleware
(
filter
,
options
);
export
default
httpProxy
;
workspaces/ui-express/server/server.ts
View file @
5a200cee
...
...
@@ -5,7 +5,8 @@ import * as express from 'express';
import
*
as
path
from
'
path
'
;
import
*
as
cookieParser
from
'
cookie-parser
'
;
import
*
as
compression
from
'
compression
'
;
import
{
readFileSync
}
from
'
fs
'
;
import
{
readFileSync
}
from
'
fs
'
;
import
multer
from
'
multer
'
;
import
config
from
'
./config
'
;
import
prerenderer
from
'
./middleware/prerenderer
'
;
...
...
@@ -17,6 +18,8 @@ import { AccessionService } from '@genesys/client/service';
import
AccessionFilter
from
'
@genesys/client/model/accession/AccessionFilter
'
;
import
geonamesHttpProxy
from
'
./middleware/geonamesHttpProxy
'
;
const
i18nextMiddleware
=
require
(
'
i18next-express-middleware
'
);
// has no proper import yet
const
upload
=
multer
();
const
app
=
express
();
// This reads the ssr-template.html compiled to ssr-compiled.html by webpack
...
...
@@ -104,7 +107,7 @@ app.use('/api', (req, res) => {
}
});
// Proxy all requests starting with /proxy
app
.
use
(
'
/proxy
'
,
httpProxy
);
app
.
use
(
'
/proxy
'
,
upload
.
none
(),
httpProxy
);
app
.
use
(
'
/proxy/api/geonames
'
,
geonamesHttpProxy
);
// Prevent access to manifest.json
app
.
use
(
/^
\/
manifest.json$/
,
(
req
,
res
)
=>
{
...
...
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