2

I created /redirect method with GET and I would like to pass URL with parameters to it like such:

/redirect/https://example.com?param=1

and then, strip parameters and respond with a redirect to:

https://example.com

That's a quite unusual situation as I see that most API requests relay on URL parameters and I intend to do the opposite. I'm conflicted if I should use Mock or Lambda.

Could someone point me in the right direction?

Thank you.

1 Answer 1

2

I think you probably want to pass the URL as a querystring parameter rather than a path parameter. I think that it would look something like this:

GET /redirect?uri=https://example.com?param=1

exports.handler = async (event, context) => {
  const Location = decodeURIComponent(event.queryStringParameters.uri);
  return {
    statusCode: 302,
    headers: { Location },
  }
};

This should return a 302 Found response with the redirect location, which should result in a browser redirect.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Daniel. It still returned parameter with your code but I changed 2 line to: const Uri = decodeURIComponent(event.queryStringParameters.uri); const Location = Uri.split('?')[0]; And it works like it should :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.