-
-
Notifications
You must be signed in to change notification settings - Fork 101
Improved README.md #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
README.md
Outdated
server.register(require('fastify-http-proxy'), { | ||
upstream, | ||
prefix: '/upstream', // optional | ||
'http://my-api.example.com', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upstream: 'http://my-api.example.com'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooops, thanks!
README.md
Outdated
const proxy = require('fastify-http-proxy') | ||
|
||
server.register(proxy, { | ||
'http://my-api.example.com', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upstream: 'http://my-api.example.com'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
README.md
Outdated
}) | ||
|
||
server.register(proxy, { | ||
'http://single-signon.example.com/auth', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upstream: 'http://my-api.example.com'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
For a more complete example, see `example.js`. | ||
This will proxy any request starting with `/api` to `http://my-api.example.com`. For instance `http://localhost:3000/api/users` will be proxied to `http://my-api.example.com/users`. | ||
|
||
If you want to have different proxies on different prefixes in you can register multiple instances of the plugin as shown in the following snippet: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you register this plugin multiple times, probably the prefix handling should be required :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, let me sure we capture this as it might be non-obvius!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you are ok with the clarification added with the latest commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
README.md
Outdated
``` | ||
|
||
For a more complete example, see `example.js`. | ||
Notice that in these case it is important to use the `prefix` option and to have *non-ambiguous* or *non-overlapping* prefixes (e.g. `/api` and `/api2`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the non-overlapping part is a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lmammino what happens if you use /api
and /api2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually not sure how prefixes are resolved and I haven't tested if this specific example is ambiguous.
Anyway, we could actually make this a little bit better by saying something like this:
Notice that in these case it is important to use the
prefix
option and to have non-ambiguous or non-overlapping prefixes (e.g. don't use/api
and/api2
but/api/
and/api2/
).
I am assuming here the second case will behave properly, but maybe it's worth updating the tests to validate these cases.
What do you think @mcollina ? Any opinion from you @delvedor ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the routing is handled by find-my-way
on our side, /api
and /api2
are two completely different routes and the overlapping should not be a problem. Given that, a test has never killed anyone :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to add a test and refactor the description if no issue is raised
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#11 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Thank you sir @delvedor ! 🤩 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Trying to improve a bit the quality of this readme with more descriptive examples and other little changes.