我使用 GET
创建了 /redirect
方法,我想将带有参数的 URL 传递给它,如下所示:
/redirect/https://example.com?param=1
然后,剥离参数并通过重定向响应:
https://example.com
这是一种非常不寻常的情况,因为我发现大多数 API 请求都传递 URL 参数,而我打算采取相反的做法。我很矛盾是否应该使用 Mock 还是 Lambda。
有人能指出我正确的方向吗?
谢谢。
最佳答案
我认为您可能希望将 URL 作为查询字符串参数而不是路径参数传递。我认为它看起来像这样:
GET/redirect?uri=https://example.com?param=1
exports.handler = async (event, context) => {
const Location = decodeURIComponent(event.queryStringParameters.uri);
return {
statusCode: 302,
headers: { Location },
}
};
这应该返回 302 Found响应重定向位置,这应该会导致浏览器重定向。
关于amazon-web-services - 如何使用AWS API Gateway从URL中剥离参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55880653/