upstream with base path doesn't work
clark0x opened this issue · 2 comments
Following example in README.md
is not work. /auth/abc
always proxy to http://single-signon.example.com/abc
.
server.register(proxy, {
upstream: 'http://single-signon.example.com/auth',
prefix: '/auth', // optional
http2: false // optional
})
UPDATED:
According to https://github.com/fastify/fastify-reply-from#base
Set the base URL for all the forwarded requests. Will be required if http2 is set to true Note that every path will be discarded.
But we do have usecase that require pass prefix to the proxy server.
@clarkorz can you write a full example of what you would like to achieve and what is currently not working? It's not exactly clear to me.
@mcollina sorry.
For example, the target url is http://api.example.com/api/v1/users/100
. So We should register a proxy like this:
server.register(proxy, {
upstream: 'http://api.example.com/api',
prefix: '/api',
})
I expect that access http://localhost:4000/api/v1/users/100
should proxy to http://api.example.com/api/v1/users/100
, but currently it's http://api.example.com/v1/users/100
which miss a base path /api
. Of cause I could change the url to http://localhost:4000/api/api/v1/users/100
to get the right url.
I used to use proxy middleware for express and webpack. It has a PathRewrite feature can do this:
{
"/api": {
"target": "https://api.example.com",
"changeOrigin": true,
"pathRewrite": {
"^/api/v1": "/api/v1",
"^/api/v2": "/api"
}
}
}