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

Allow request.params variable replacement in the uri template #44

Merged
merged 4 commits into from Oct 9, 2016

Conversation

@EyePulp
Copy link
Contributor

EyePulp commented Oct 6, 2016

Make it possible to insert request.params values in your custom uri. Doesn't clobber any of the previously defined template options: {protocol},{host},{port} or {path}.

Usage

server.route({ 
    path: '/foo/bar/{image_name}', 
    method:'GET', 
    handler:{
        proxy: {
            uri  : 'https://s3.amazonaws.com/some.random.bucket/folder/{image_name}'
        }
    }
}),
README.md Outdated
path: '/',
handler: {
proxy: {
uri: '{protocol}:{port}//{host}/use/the/{path}'

This comment has been minimized.

Copy link
@osukaa

osukaa Oct 7, 2016

Contributor

I'm not sure what you're trying to create an example here. I think this returns

http:8080//example/use/the/

This comment has been minimized.

Copy link
@EyePulp

EyePulp Oct 8, 2016

Author Contributor

Sorry - transposition error. I'll fix it.

@osukaa osukaa added this to the 5.3.0 milestone Oct 7, 2016
@EyePulp

This comment has been minimized.

Copy link
Contributor Author

EyePulp commented Oct 8, 2016

@osukaa Please take a look and see if the doc improvements are to your liking. Thanks!

@osukaa
osukaa approved these changes Oct 9, 2016
@osukaa osukaa merged commit 06317c4 into hapijs:master Oct 9, 2016
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@osukaa

This comment has been minimized.

Copy link
Contributor

osukaa commented Oct 9, 2016

@EyePulp v5.3.0 is published :)

Object.keys(request.params).forEach((key) => {

const re = new RegExp(`{${key}}`,'g');
address = uri.replace(re,request.params[key]);

This comment has been minimized.

Copy link
@kanongil

kanongil Oct 9, 2016

Member

This line removes all previous address replacements, including other params replacements. It will break existing code that uses replacements with a dynamic path segment.

This comment has been minimized.

Copy link
@osukaa

osukaa Oct 9, 2016

Contributor

I unpublished the v5.3.0. We'll need an update for this

This comment has been minimized.

Copy link
@osukaa

osukaa Oct 9, 2016

Contributor

cc/ @EyePulp

This comment has been minimized.

Copy link
@EyePulp

EyePulp Oct 9, 2016

Author Contributor

@kanongil Can you provide an example? I'm guessing you mean something other than the {protocol}, {host} etc replacements, but I'm not sure.

This comment has been minimized.

Copy link
@kanongil

kanongil Oct 10, 2016

Member

No I'm not. If you add a test that contains multiple params replacements, or combines it with eg. a {protocol} replacement, it fails horribly.

Basically, you just need to change uri to address to fix it.

This comment has been minimized.

Copy link
@EyePulp

EyePulp Oct 10, 2016

Author Contributor

@kanongil Great catch, and a dumb mistake on my part. Thank you. @osukaa -- Making a PR with the fix and some additional tests to verify with multiple replacements occurring.

@Marsup Marsup removed the request label Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.