我正在尝试在Google Cloud Functions上部署cors-anywhere。我应该在gcp的链接后提供网址。
它看起来像这样:
https://us-central1-my-project.cloudfunctions.net/my-function / http://dummy.restapiexample.com/api/v1/employees
但已转换为:
https://us-central1-my-project.cloudfunctions.net/my-function /http:/dummy.restapiexample.com/api/v1/employees
将主机后的所有双斜杠转换为简单的双斜杠。
我尝试替换 req.url 将 http:/ 转换为 http:// ,但仍然无法正常工作。也许需要在网络服务器级别对此进行修复。
这是我在GCP中的职能
var cors_proxy = require('cors-anywhere').createServer({
requireHeader: ['origin', 'x-requested-with'],
removeHeaders: [
'cookie',
'cookie2',
],
// See README.md for other options
});
exports.myFunction = (req, res) => {
req.url = req.url.replace('/my-function/', '/'); // Strip '/my-function' from the front of the URL, else the proxy won't work.
return cors_proxy.emit('request', req, res);
};
有人试图在无服务器功能中部署它吗?
答案 0 :(得分:0)
您正在使用req.url
,其中包含请求URL的规范化版本。您将要使用req.originalUrl
,顾名思义,它保留了原始请求的URL。有关更多信息,请参见Express docs。