Skip to content

Commit 15ce3e7

Browse files
authored
README: Corrected confusing example (#98)
`upstream` is passed as `base` to `fastify-reply-from`. Quoting `fastify-reply-form` doc: > *base* > Set the base URL for all the forwarded requests. Will be required if http2 is set to true Note that path will be discarded. So, specifying `/auth` in `upstream` has no effect at all, but this example seems to suggest `/auth/user` requests will be forwarded to `http://single-signon.example.com/auth/user`, when the real target will be `http://single-signon.example.com/user`.
1 parent 76bb3c7 commit 15ce3e7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,18 @@ const Fastify = require('fastify')
4646
const server = Fastify()
4747
const proxy = require('fastify-http-proxy')
4848

49+
// /api/x will be proxied to http://my-api.example.com/x
4950
server.register(proxy, {
5051
upstream: 'http://my-api.example.com',
5152
prefix: '/api', // optional
5253
http2: false // optional
5354
})
5455

56+
// /auth/user will be proxied to http://single-signon.example.com/signon/user
5557
server.register(proxy, {
56-
upstream: 'http://single-signon.example.com/auth',
58+
upstream: 'http://single-signon.example.com',
5759
prefix: '/auth', // optional
60+
rewritePrefix: '/signon', // optional
5861
http2: false // optional
5962
})
6063

@@ -63,6 +66,8 @@ server.listen(3000)
6366

6467
Notice that in this case it is important to use the `prefix` option to tell the proxy how to properly route the requests across different upstreams.
6568

69+
Also notice paths in `upstream` are ignored, so you need to use `rewritePrefix` to specify the target base path.
70+
6671
For other examples, see `example.js`.
6772

6873
## Options

0 commit comments

Comments
 (0)