json-server running but can't access its api due to 403

Viewed 911

Learning reactjs, trying to simulate a server with json-server
this is my script to run the server:

"scripts": {
    "server": "json-server --watch db.json --port 5000"
},

running this on terminal npm run server
output:

Debugger listening on ws://127.0.0.1:61616/507f7893-92a9-4526-b8f4-a3e71cfa4c62
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.

> my-app@0.1.0 server
> json-server --watch db.json --port 5000

Debugger listening on ws://127.0.0.1:61629/8a2f877f-f4bd-465e-b454-01a63eabb40a
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.

  \{^_^}/ hi!

  Loading db.json
  Done

  Resources
  http://localhost:5000/tasks

  Home
  http://localhost:5000

  Type s + enter at any time to create a snapshot of the database
  Watching...

now when I try to access http://localhost:5000/tasks , I get 403 Access to localhost was denied.
what can I do to fix this?
Thanks!

2 Answers

the problem was with the port. changed it to 3001 and it works. still doesn't understand why did this happen in that port.

Maybe you are using MacOS Monterey(or maybe other versions in the future). Check the reason here: https://developer.apple.com/forums/thread/682332

Cause: Control Center on Monterey listening to port 5000 and port 7000

Fix: change the port to avoid range 5000-7000, like following,

"server": "json-server --watch db.json --port 3000"

or just remove the customised argument --port 3000 as this is the default value

Related