Skip to content
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

added support for dynamical upstream configuration #178

Merged
merged 3 commits into from
Aug 12, 2021

Conversation

nettema
Copy link
Contributor

@nettema nettema commented Aug 10, 2021

added support for dynamical upstream configuration
replyOptions.getUpstream must be specified for this

These changes allow using getUpstream feature of fastify-reply-from library to change upstream dynamically

replyOptions.getUpstream must be specified for this
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.

Can you please add a unit test and docs?

index.js Outdated Show resolved Hide resolved
@nettema nettema requested review from Eomm and mcollina August 11, 2021 22:45
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

index.js Outdated
@@ -117,7 +117,7 @@ function generateRewritePrefix (prefix, opts) {
return ''
}

let rewritePrefix = opts.rewritePrefix || new URL(opts.upstream).pathname
let rewritePrefix = opts.rewritePrefix || new URL(opts.upstream || 'http://empty').pathname
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this http://empty default value avoidable?

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 so, we should just use a default pathname if no upstream is there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to provide any valid upstream to URL constructor, in another case, we'll have to handle the exception that the URL constructor will throw.

Copy link
Member

Choose a reason for hiding this comment

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

I mean if there is no opts.upstream, jut specify / as the rewritePrefix. We can skip parsing the URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

new URL('http://empty').pathname this construction should return /.
Another way to solve this situation is to additionally check upstream and code will be looking like that:
let rewritePrefix = opts.rewritePrefix || opts.upstream ? new URL(opts.upstream).pathname : '/'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if the second option is preferred I can update that part.

Copy link
Member

Choose a reason for hiding this comment

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

To me it looks more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have refactored rewritePrefix as requested.

@nettema nettema requested a review from zekth August 12, 2021 10:19
Copy link
Member

@zekth zekth left a comment

Choose a reason for hiding this comment

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

Lgtm. Thanks

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 74fe6c9 into fastify:master Aug 12, 2021
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.

None yet

4 participants