How to run WEP API Node and a Reactjs Project on the same machine?

Asked

Viewed 23 times

0

I have running a Web API at the address localhost:3333 and a Reactjs Application at localhost:3000, however when I try to perform some request with fetch the browser returns Cors error. Is there any config to ignore this behavior?

inserir a descrição da imagem aqui

1 answer

3


You can change this behavior by downloading some extensions to your browser, but in general it is advisable that on your server you send in the response header the value Access-Control-Allow-Origin, there’s an express middleware for that.

$ npm install cors

In your server settings you do so:

const express = require("express");
const cors = require("cors");

const app = express();

app.use(cors());

Browser other questions tagged

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