我试图在Google函数上部署cors-任何地方。我应该在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:/转换为,但仍然无法工作。也许这需要在the服务器级别进行修复。
这是我在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);
};有人试图将其部署到无服务器功能中吗?
发布于 2019-07-11 18:35:16
您使用的是req.url,它包含请求URL的规范化版本。您将需要使用req.originalUrl,顾名思义,它保留了原始请求的URL。有关更多信息,请参见特快文档。
https://stackoverflow.com/questions/56994726
复制相似问题