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

How can I add query params in plugin #110

Closed
mofazhe opened this issue Apr 1, 2024 · 3 comments
Closed

How can I add query params in plugin #110

mofazhe opened this issue Apr 1, 2024 · 3 comments

Comments

@mofazhe
Copy link
Contributor

mofazhe commented Apr 1, 2024

I based on this request definition of parameters:
image

Here is my code of plugin:

function handleRequest() {
    // console.log(context.request.getBody())

    var timestamp=Date.now();
    console.log(timestamp)
    context.request.setEnvironmentVariable('timestamp', timestamp)
    var params=context.request.getQueryParams();
    console.log(params)
    params.push({"name":"time","value":"1232"});
    console.log(params)
    context.request.setQueryParams(params);
}

if('request' in context) {
    handleRequest()
}

But, here is the result:
318422396-e7c0d980-e9d7-42ae-b8f1-e4fda060b717-1
318422396-e7c0d980-e9d7-42ae-b8f1-e4fda060b717-2

Changes to environment variables in handleRequest also do not take effect in the request parameters, see the environment variable timestamp above.

Editing is only because the picture may leak privacy, please ignore it. Sorry for disturbing you.

@flawiddsouza
Copy link
Owner

Changes to environment variables in handleRequest also do not take effect in the request parameters, see the environment variable timestamp above.

This is now fixed.

This should work:

const queryParams = context.request.getQueryParams()
context.request.setQueryParams([...queryParams, { name: 'cat', value: '3' }])

image

Your code should work but looks like there's a limitation in the underlying library that I'm using for running plugins. I'll look into fixing that.

@mofazhe
Copy link
Contributor Author

mofazhe commented Apr 2, 2024

Changes to environment variables in handleRequest also do not take effect in the request parameters, see the environment variable timestamp above.

This is now fixed.

I will try it in next version.

This should work:

const queryParams = context.request.getQueryParams()
context.request.setQueryParams([...queryParams, { name: 'cat', value: '3' }])

I tried the code and it worked fine.

Your code should work but looks like there's a limitation in the underlying library that I'm using for running plugins. I'll look into fixing that.

That would be great.

@flawiddsouza
Copy link
Owner

Closing this for now, as there's a workaround. I'll try to fix the query params direct usage issue in the next release. A new version has been released. It has the fix for the environment variable issue you reported.

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

No branches or pull requests

2 participants