Skip to content

Conversation

lmammino
Copy link
Member

@lmammino lmammino commented Jul 14, 2018

Trying to improve a bit the quality of this readme with more descriptive examples and other little changes.

Copy link
Member

@mcollina mcollina left a 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',
Copy link
Member

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'

Copy link
Member Author

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',
Copy link
Member

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'

Copy link
Member Author

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',
Copy link
Member

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'

Copy link
Member Author

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:
Copy link
Member

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 :)

Copy link
Member Author

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!

Copy link
Member Author

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

Copy link
Member

@mcollina mcollina left a 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`).
Copy link
Member

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.

Copy link
Member

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?

Copy link
Member Author

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 ?

Copy link
Member

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

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#11 :)

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@lmammino
Copy link
Member Author

Thank you sir @delvedor ! 🤩

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit d52b2fc into fastify:master Jul 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants