简体   繁体   English

从 Node JS 获取 API 时出现 CORS 错误

[英]I am getting CORS error while fetching API from Node JS

I am getting issue while fetching Node API using GET method.我在使用 GET 方法获取节点 API 时遇到问题。 This issue is related to CORS but don't know how to resolve it.此问题与 CORS 有关,但不知道如何解决。 Here is the screenshot of the error which i am getting.这是我得到的错误的屏幕截图。

在此处输入图像描述

And here is the react code where I am trying to fetch data from API.这是我试图从 API 获取数据的反应代码。

反应代码

And here is my node API code.这是我的节点 API 代码。

节点 API 代码

Allow cors from your Node.JS entry file.从您的 Node.JS 入口文件中允许 cors。 npm i cors.Import const cors = require('cors'), With express after asigning express instance to a variable holder. npm i cors.Import const cors = require('cors'),将 express 实例分配给变量持有者后使用 express。 allow express to use cors.允许快递使用cors。 app.use(cors()) app.use(cors())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在 Node js 中的 heroku 上收到 CORS 错误 - I am getting CORS error on heroku in Node js 为什么我在安装节点 js 时收到此错误 - why i am getting this error while installing node js 为什么我从node.js收到此错误? - Why am I getting this error from node.js? 从Ionic框架连接到Node JS服务时遇到CORS错误 - Getting CORS error while connecting to a node js service from ionic framework 使用 express node.js 更新数据时出现错误 - i am getting an error while i am updating my data using express node.js 使用 monogoose 将 object 推送到节点 js 中的数组属性时出现错误 - I am getting an error while i am pushing an object to the array property in node js using monogoose 使用node js从mongdb提取数据时出现404错误 - getting 404 error while fetching data from mongdb using node js 使用 Express/Node.js 从 Mongo DB 获取数据时出现 404 错误 - Getting 404 error while fetching data from Mongo DB using Express/Node.js 在 Flutter 中从 Node.js rest api 获取数据时出错(Mysql Localhost) - Error while fetching data from Node.js rest api in Flutter ( Mysql Localhost) 从Lambda函数节点js中的api获取响应时获取错误 - Gettting error while fetching response from api in lambda function node js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM