node.js - 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;
}
},```
解决方案
推荐阅读
- html - 如何停止我的
- 元素在悬停在另一个上时移动
- ?
- javascript - JS 文件在打开后未在模态视图中加载
- python - 从对象数组中获取所有对象的特定属性的数组
- angular - 类型定义中的感叹号
- tensorflow - 如何在我的代码中使用张量核心而不是 cuda 核心?
- java - 在枚举中添加长方法是不好的设计吗?
- javascript - 调用 e.preventDefault() 后提交复选框表单
- html - 当显示设置为内联时,边距顶部不起作用
- javascript - 使用Router和Links在同一个地方渲染所有组件
- ruby - Savon ruby gem 的“dh 键太小”