将 Uri 中的大写字母替换为小写



我不确定这是否是正确的位置,但我是第一次使用 AWS。我正在尝试更新请求 Uri 以删除所有大写字母的实例。由于有些人与他们一起连接到我的网站>.<</p>

替换我的 Uri 时,我的函数是

request.uri = request.uri .replace (//cokr//,'') .replace (//G/,’/g');

也试过

request.uri = request.uri.toLowerCase();

任何建议将不胜感激,因为第一个替换不起作用,第二个则不工作并导致 502 错误。请不要知道为什么替换字符串似乎不能正常工作。

502 错误请求无法得到满足。Lambda 函数结果验证失败:指定的 URI 格式无效。

通过在新字符串上执行所有操作然后返回相同的内容来修复。

"使用严格";

exports.handler = (event, context, callback) => { 常量请求 = 事件。记录[0].cf.request;

var cleanPath = "";
cleanPath = request.uri.toLowerCase();
console.log("clean path is : " + cleanPath);
cleanPath = cleanPath.replace('/cokr/','/');
console.log("clean path is now : " + cleanPath);
request.uri = cleanPath;
console.log("request uri is : " + request.uri);
return callback(null, request);

};

最新更新