15

I have a little NodeExpress server and when I try to make a request to the server it returns a 403 error I have installed Cors and used it and tried with chrome browser and Postman as 2 clients and got the same denied error

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

app.use(cors())

app.get('/', function (req, res, next) {
  res.json({msg: 'This is CORS-enabled for all origins!'})
})

app.listen(80, function () {
  console.log('CORS-enabled web server listening on port 80')
})
Yusuf
  • 2,295
  • 7
  • 15
  • 34

5 Answers5

41

I was having this having this problem with using firebase serve on MacBook Pro (14-inch, 2021), Apple M1 Pro, macOS Monterey 12.3

UPDATE:

so apparently the reason was

macOS Monterey introduced AirPlay Receiver running on port 5000. This prevents your web server from serving on port 5000. Receiver already has the port.

so the solution proposed by the answer quoted above, was to either turn off the AirPlay Receiver, or to run your app on another port.

if you are running your app using firebase serve, You can change the port by following this approach:

source

firebase.json file doesn't work with the the firebase serve command. You have to use the firebase emulators:start command.

If you want to keep using firebase serve then it should be use like in:

firebase serve --only hosting --port=5002

OLD ANSWER:

Not a sufficient answer, but I was able to bypass this by entering 127.0.0.1 instead of localhost. I don't think this is the best answer, neither I am satisfied with it. I'll definitely come back later and update the answer once I find a better answer.

Adnan
  • 906
  • 13
  • 30
3

for Chrome try this

chrome://net-internals/#sockets

you will be displayed tiny webpage like this:

enter image description here

click [Flush socket pools]

andilabs
  • 22,159
  • 14
  • 114
  • 151
Mandeep Singh
  • 455
  • 2
  • 14
1

just use another port e.g. 5100

"sampleApp": {
  "commandName": "Project",
  "launchBrowser": true,
  "launchUrl": "weatherforecast",
  "applicationUrl": "http://localhost:5100",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}
LeRoy
  • 4,189
  • 2
  • 35
  • 46
0

Sometimes I had the same issue when developing FLASK application on Monterey and using Chrome. A restart of Chrome always solved the issue. I suppose that not stopping the application properly is the root cause in my case.

thhappy
  • 13
  • 2
0

I've just encountered this issue. My stack was Node + Express

With this stack, above solution works as well.

All I had to do was to change the port number:

app.listen(5000); // does not work

app.listen(8000); // all good :)

David Maze
  • 130,717
  • 29
  • 175
  • 215
AdamKniec
  • 1,607
  • 9
  • 25