首页 > 解决方案 > Google Functions 发布请求错误 - 请求未通过访问控制检查:它没有 HTTP ok 状态

问题描述

我正在编写一个 VueJs/NodeJS 应用程序,并试图获取我当前部署的 Google 函数。我正在找回这个错误,我一生都无法弄清楚如何解决它。我已经添加resp.set('Access-Control-Allow-Origin',*)到我的后端并修改了获取请求,如此处所示,标题中的这一行也是如此,但仍然没有解决这个错误。对苦苦挣扎的小学生有什么建议吗?

      try {
        this.$emit("loading", true);
        console.log("getting the scraper");
        console.log(`here is input ${input}`);
        //" "
        const response = await fetch(
          "https://us-central1-mvp-web-scraper.cloudfunctions.net/webScrape",
          {
            method: "POST",
            mode: "cors",
            //tells the server that I am adding some data to it, it is in the form of text which is easy for a machine to parse and read
            headers: {
              "Content-Type": "application/json",
              "Allow-control-allow-origin": "*",
            },
            body: JSON.stringify({ input }),
          }
        );
        // console.log(response);
        const data = await response.json();
        console.log("Here is the data received at - SearchBar.vue");
        console.log(data);
        this.$emit("data", data);
        this.$emit("loading", false);
        return data;
      } catch (error) {
        console.log("an error occurred on the client side");
        console.log(error);
        this.error = true;
        this.$emit("loading", false);

        return error;
      }
    },```

标签: node.jsfunctionvue.jsfetchcloud

解决方案


推荐阅读