79111859

Date: 2024-10-21 21:57:11
Score: 0.5
Natty:
Report link

Sorry, I'm answering my own question. I found a solution and it's one I hadn't seen before in any of the posts related to this problem, perhaps because it's on express verion 4.21.1:

Simply change the following:

const express = require('express');
const app = express();
const port = 3100;

app.use(express.json());

To this:

const express = require('express');
const app = express();
var cors = require('cors')
const port = 3100;

app.use(cors())

app.use(express.json());

you must load the cors pakage with

npm install cors

and see:

https://github.com/expressjs/cors?tab=readme-ov-file#enabling-cors-pre-flight

for more information.

With that I could remove the mode: no-cors line from then origin fetch.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: David Pawlak