Blocked cross-origin request when creating a box

Asked

Viewed 254 times

0

Hello I’m starting in React and I came across a problem, I’m trying to make an app similar to Dropbox, on the main screen you create a box and can upload files, but when I click create this message appears:

"Blocked cross-origin request: Same Origin Policy (Same Origin Policy) prevents reading the remote resource at https://app-reactteste.herokuapp.com/boxes. (Reason: CORS header 'Access-Control-Allow-Origin' is not present)."

I saw that there is a CORS extension for the browser, activated and appears error 503, I wonder if this is usually an error in the same code?

The back-end is on github: https://github.com/onz3/backend

  • You are passing header on request from the front?

1 answer

0

Possibly your problem is in the backend. Add the library cors. In this case it is a middleware. The configuration is very simple according to the documentation.

var express = require('express')
var cors = require('cors')
var app = express()

app.use(cors())
  • Oh yes it is that already this certificate that: const express = require("express"); const Mongoose = require("Mongoose"); const path = require("path"); const Cors = require("Cors"); but continues with the same error const app = express(); app.use(Cors());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.