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
Hide 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 @@
...
@@ -58,11 +58,11 @@
"debug"
:
"^4.1.1"
,
"debug"
:
"^4.1.1"
,
"es-cookie"
:
"^1.3.2"
,
"es-cookie"
:
"^1.3.2"
,
"express"
:
"^4.17.1"
,
"express"
:
"^4.17.1"
,
"express-http-proxy"
:
"^1.6.0"
,
"fast-glob"
:
"^3.2.2"
,
"fast-glob"
:
"^3.2.2"
,
"flattenjs"
:
"^2.0.0"
,
"flattenjs"
:
"^2.0.0"
,
"form-data"
:
"^3.0.0"
,
"form-data"
:
"^3.0.0"
,
"history"
:
"^4.10.1"
,
"history"
:
"^4.10.1"
,
"http-proxy-middleware"
:
"^1.0.6"
,
"i18next"
:
"^19.4.0"
,
"i18next"
:
"^19.4.0"
,
"i18next-browser-languagedetector"
:
"^4.0.2"
,
"i18next-browser-languagedetector"
:
"^4.0.2"
,
"i18next-express-middleware"
:
"^1.9.1"
,
"i18next-express-middleware"
:
"^1.9.1"
,
...
@@ -76,6 +76,7 @@
...
@@ -76,6 +76,7 @@
"lodash"
:
"^4.17.19"
,
"lodash"
:
"^4.17.19"
,
"minimist"
:
"^1.2.5"
,
"minimist"
:
"^1.2.5"
,
"moment"
:
"^2.24.0"
,
"moment"
:
"^2.24.0"
,
"multer"
:
"^1.4.2"
,
"normalize.css"
:
"^8.0.1"
,
"normalize.css"
:
"^8.0.1"
,
"prop-types"
:
"^15.7.2"
,
"prop-types"
:
"^15.7.2"
,
"query-string"
:
"^6.12.0"
,
"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
config
from
'
../config
'
;
import
{
Request
}
from
'
express
'
;
const
geonamesApiUrl
=
'
https://secure.geonames.org
'
;
const
geonamesApiUrl
=
'
https://secure.geonames.org
'
;
const
geonamesHttpProxy
=
proxy
(
geonamesApiUrl
,
{
const
geonamesHttpProxy
=
createProxyMiddleware
(
{
parseReqBody
:
false
,
target
:
geonamesApiUrl
,
proxyReqPathResolver
:
(
req
)
=>
{
pathRewrite
:
(
path
:
string
,
req
:
Request
)
=>
{
const
path
=
`
${
req
.
url
}
&username=
${
config
.
geonamesUsername
}
`
;
let
updatedPath
=
path
.
replace
(
'
/proxy/api/geonames
'
,
''
);
updatedPath
=
`
${
updatedPath
}
&username=
${
config
.
geonamesUsername
}
`
;
// remove all headers from request
// remove all headers from request
req
.
headers
=
{};
delete
req
.
headers
;
console
.
log
(
`
HTTP proxy to
${
geonamesApiUrl
}${
updatedPath
}
`
);
console
.
log
(
`
HTTP proxy to
${
geonamesApiUrl
}${
path
}
`
);
return
updatedPath
;
return
path
;
},
},
});
});
...
...
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
config
from
'
../config
'
;
import
refreshAuthToken
from
'
./refreshAuthToken
'
;
import
refreshAuthToken
from
'
./refreshAuthToken
'
;
const
httpProxy
=
proxy
(
config
.
apiUrl
,
{
import
{
createProxyMiddleware
}
from
'
http-proxy-middleware
'
;
parseReqBody
:
false
,
timeout
:
config
.
apiTimeout
,
filter
:
(
req
,
res
)
=>
{
const
filter
=
(
path
:
string
,
req
:
Request
)
=>
{
if
(
req
.
url
.
startsWith
(
'
/oauth/
'
)
||
req
.
url
.
startsWith
(
'
/token
'
)
||
req
.
url
.
startsWith
(
'
/google
'
))
{
if
(
req
.
url
.
startsWith
(
'
/oauth/
'
)
||
req
.
url
.
startsWith
(
'
/token
'
)
||
req
.
url
.
startsWith
(
'
/google
'
))
{
// console.log('Will proxy /oauth');
console
.
log
(
'
Will proxy /oauth
'
);
if
(
req
.
query
.
grant_type
===
'
refresh_token
'
&&
!
req
.
query
.
refresh_token
)
{
return
true
;
refreshAuthToken
(
req
,
res
);
}
return
true
;
// Not proxying the request
}
console
.
log
(
`
Not proxying
${
req
.
url
}
`
);
return
true
;
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
}
`
;
}
}
// Not proxying the request
console
.
log
(
`
Not proxying
${
req
.
url
}
`
);
console
.
log
(
`
HTTP proxy to
${
config
.
apiUrl
}${
updatedPath
}
`
);
return
false
;
return
updatedPath
;
},
},
proxyReqPathResolver
:
(
req
)
=>
{
onProxyReq
(
proxyReq
:
ClientRequest
,
req
:
Request
,
res
:
Response
)
{
let
path
=
req
.
url
;
if
(
proxyReq
.
path
.
startsWith
(
'
/oauth/token
'
))
{
if
(
path
.
startsWith
(
'
/oauth/token
'
))
{
if
(
req
.
query
.
grant_type
===
'
refresh_token
'
&&
!
req
.
query
.
refresh_token
)
{
const
grantType
=
req
.
query
.
grant_type
;
console
.
log
(
'
refreshAuthToken
'
);
if
(
grantType
===
'
client_credentials
'
||
grantType
===
'
password
'
||
grantType
===
'
refresh_token
'
)
{
refreshAuthToken
(
req
,
res
);
path
=
`
${
path
}
&client_id=
${
config
.
clientId
}
&client_secret=
${
config
.
clientSecret
}
`
;
}
}
}
else
if
(
path
.
startsWith
(
'
/google/verify-token
'
))
{
path
=
`
${
path
}
&clientId=
${
config
.
clientId
}
`
;
}
console
.
log
(
`
HTTP proxy to
${
config
.
apiUrl
}${
path
}
`
);
const
form
=
new
FormData
();
return
path
;
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
;
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
;
export
default
httpProxy
;
workspaces/ui-express/server/server.ts
View file @
5a200cee
...
@@ -5,7 +5,8 @@ import * as express from 'express';
...
@@ -5,7 +5,8 @@ import * as express from 'express';
import
*
as
path
from
'
path
'
;
import
*
as
path
from
'
path
'
;
import
*
as
cookieParser
from
'
cookie-parser
'
;
import
*
as
cookieParser
from
'
cookie-parser
'
;
import
*
as
compression
from
'
compression
'
;
import
*
as
compression
from
'
compression
'
;
import
{
readFileSync
}
from
'
fs
'
;
import
{
readFileSync
}
from
'
fs
'
;
import
multer
from
'
multer
'
;
import
config
from
'
./config
'
;
import
config
from
'
./config
'
;
import
prerenderer
from
'
./middleware/prerenderer
'
;
import
prerenderer
from
'
./middleware/prerenderer
'
;
...
@@ -17,6 +18,8 @@ import { AccessionService } from '@genesys/client/service';
...
@@ -17,6 +18,8 @@ import { AccessionService } from '@genesys/client/service';
import
AccessionFilter
from
'
@genesys/client/model/accession/AccessionFilter
'
;
import
AccessionFilter
from
'
@genesys/client/model/accession/AccessionFilter
'
;
import
geonamesHttpProxy
from
'
./middleware/geonamesHttpProxy
'
;
import
geonamesHttpProxy
from
'
./middleware/geonamesHttpProxy
'
;
const
i18nextMiddleware
=
require
(
'
i18next-express-middleware
'
);
// has no proper import yet
const
i18nextMiddleware
=
require
(
'
i18next-express-middleware
'
);
// has no proper import yet
const
upload
=
multer
();
const
app
=
express
();
const
app
=
express
();
// This reads the ssr-template.html compiled to ssr-compiled.html by webpack
// This reads the ssr-template.html compiled to ssr-compiled.html by webpack
...
@@ -104,7 +107,7 @@ app.use('/api', (req, res) => {
...
@@ -104,7 +107,7 @@ app.use('/api', (req, res) => {
}
}
});
});
// Proxy all requests starting with /proxy
// Proxy all requests starting with /proxy
app
.
use
(
'
/proxy
'
,
httpProxy
);
app
.
use
(
'
/proxy
'
,
upload
.
none
(),
httpProxy
);
app
.
use
(
'
/proxy/api/geonames
'
,
geonamesHttpProxy
);
app
.
use
(
'
/proxy/api/geonames
'
,
geonamesHttpProxy
);
// Prevent access to manifest.json
// Prevent access to manifest.json
app
.
use
(
/^
\/
manifest.json$/
,
(
req
,
res
)
=>
{
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