-
Notifications
You must be signed in to change notification settings - Fork 87
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
Conversation
replyOptions.getUpstream must be specified for this
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.
Can you please add a unit test and docs?
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
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 |
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.
Isn't this http://empty
default value avoidable?
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 so, we should just use a default pathname if no upstream is there.
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.
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.
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 mean if there is no opts.upstream
, jut specify /
as the rewritePrefix
. We can skip parsing the URL.
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.
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 : '/'
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.
So if the second option is preferred I can update that part.
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.
To me it looks more readable
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 have refactored rewritePrefix as requested.
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. Thanks
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
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