简体   繁体   English

Node.js:请求的资源上不存在“Access-Control-Allow-Origin”header

[英]Node.js: No 'Access-Control-Allow-Origin' header is present on the requested resource

I'm newer to cors and exactly what you need.我对 cors 较新,这正是您所需要的。 I had an app working live a couple of months ago and it seems like it has broken due to CORS.几个月前我有一个应用程序正在运行,它似乎由于 CORS 而损坏。 Every time I make a request I get the error: "as been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."每次我提出请求时,我都会收到错误消息:“被 CORS 政策阻止:请求的资源上不存在‘Access-Control-Allow-Origin’ header。”

Here is my server cors code:这是我的服务器 cors 代码:

const express = require("express");
const jwt = require("jsonwebtoken");
const cors = require('cors');

const app = express();

// Set Port
app.set("port", process.env.PORT || 5000);

// Listen
app.listen(process.env.PORT || 5000);

// Load Middlewear
app.use(express.urlencoded({ extended: true }));
app.use(express.json()); // To parse the incoming requests with JSON payloads

// CORS HEADERS MIDDLEWARE
var corsOptions = {
    origin: '*',
    optionsSuccessStatus: 200,
  }
app.use(cors(corsOptions));

You need to allow the back to accept only by the front like this您需要像这样只允许背面接受正面

`` var corsOptions = { origin: 'http://localhost:8080' front ip or dns } `` var corsOptions = { origin: 'http://localhost:8080' 前面 ip 或 dns }

app.use(cors(corsOptions) `` app.use(cors(corsOptions) ``

暂无
暂无

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

相关问题 Node.js中node-static中请求的资源上没有“Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource in node-static in Node.js Node.JS/Fetch:请求的资源上不存在“Access-Control-Allow-Origin”header - Node.JS/Fetch: No 'Access-Control-Allow-Origin' header is present on the requested resource 无法在NODE.JS中解决此问题,请求的资源在(nodejs + angularjs)中不存在“ Access-Control-Allow-Origin”标头 - Unable to solve this in NODE.JS, No 'Access-Control-Allow-Origin' header is present on the requested resource in (nodejs + angularjs) Node.js中的请求资源上没有“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource in Node.js Node js Heroku 请求的资源上不存在“Access-Control-Allow-Origin”标头 - Node js Heroku No 'Access-Control-Allow-Origin' header is present on the requested resource Node.Js 错误“请求中不存在‘Access-Control-Allow-Origin’标头” - Node.Js error “No 'Access-Control-Allow-Origin' header is present on the requested” 角度:请求的资源上不存在“Access-Control-Allow-Origin”标头 - ANGULAR: No 'Access-Control-Allow-Origin' header is present on the requested resource Access-Control-Allow-Origin'标头出现在请求的资源上 - Access-Control-Allow-Origin' header is present on the requested resource NodeJ在所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - NodeJs No 'Access-Control-Allow-Origin' header is present on the requested resource Angular 6 - 请求的资源上不存在“Access-Control-Allow-Origin”标头 - Angular 6 - No 'Access-Control-Allow-Origin' header is present on the requested resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM