【问题标题】:Cross origin error when using cloud functions in back4app在 back4app 中使用云功能时出现跨源错误
【发布时间】:2019-10-30 12:22:59
【问题描述】:
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';    
 });

【问题讨论】:

    标签: back4app


    【解决方案1】:

    可能与 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';
    });
    
    • 检查您是否在前端初始化了正确的键。

    如果还是不行,请在实时聊天中联系Back4App团队=D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-18
      • 2020-01-03
      • 2021-02-24
      • 2019-09-30
      • 2021-01-28
      • 1970-01-01
      • 2019-07-26
      • 1970-01-01
      相关资源
      最近更新 更多