Getting CORS error when calling cloud function in back4app.
Error:
在访问XMLHttpRequest'https://parseapi.back4app.com/functions/hello'来自原点'http://localhost:8100'已被CORS策略阻止:No'访问-请求的资源上存在"Control-Allow Origin"标头。
In client code cloud function implemented in home page
home.page.ts:
Parse.Cloud.run('hello').then(function (ratings) {
console.log("updated");
}).catch((error) => {
console.log(error);
console.log("fail");
});
Cloud function:
In back4app added main.js file with cloud code implementation
main.js:
Parse.Cloud.define('hello', function(req, res) {
Parse.Cloud.useMasterKey();
return 'Hi';
});
它可以与Parse Server版本相关。
你能看看你正在使用的解析服务器版本是什么吗?请按照本指南查找此信息。
如果是2.X,则必须部署具有以下结构的函数:
main.js
:
Parse.Cloud.define('hello', function(req, res) {
response.success('Hello')
});
不赞成使用代码Parse.Cloud.useMasterKey();
。点击此处阅读更多信息。
如果是3.X,你可以部署一些类似的东西:
Parse.Cloud.define('hello', (req) => {
return 'Hello';
});
- 检查是否已初始化前端侧的正确密钥
如果仍然不起作用,请在实时聊天=D 中联系Back4App团队