Getting CORS error when calling cloud function in back4app.
Error:
在以下位置访问XMLHttpRequest 原产地的“ https://parseapi.back4app.com/functions/hello” “ http://localhost:8100”已被CORS政策禁止:否“访问- 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';
});
答案 0 :(得分:0)
它可能与Parse Server版本有关。
能否请您查看一下正在使用的Parse Server版本?请在this guide之后找到此信息。
如果是2.X,则必须部署具有以下结构的函数:
main.js
:
Parse.Cloud.define('hello', function(req, res) {
response.success('Hello')
});
不建议使用代码Parse.Cloud.useMasterKey();
。了解更多here。
如果是3.X,则可以部署以下内容:
Parse.Cloud.define('hello', (req) => {
return 'Hello';
});
如果仍然无法使用,请通过在线聊天= D与Back4App团队联系