Access to localhost was denied | You don't have authorization to view this page. HTTP ERROR 403
Matthew C.
—When running a local development server for a Node.js app, you may get the following error in your browser:
Access to localhost was denied You don't have authorization to view this page. HTTP ERROR 403
This occurs when you don’t have access rights. For example, you would encounter a 403
error when sending a request to a protected API endpoint without the required access token.
Let’s address five common reasons you may be denied access to the localhost:
If your API endpoint requires authentication, check that the access token in your request is correct and that you have the required permissions. For example, an admin-only endpoint would require admin permissions.
To connect to the localhost web server, you need to provide both the IP address and the port number:
127.0.0.1:5000
If the port is already in use, you won’t be able to access your local development server. Check that the port is not being used by another server or application.
If you use port 5000
or 7000
on a machine running macOS version 12 (Monterey) or above, the issue may caused by the macOS AirPlay Receiver, which runs on port 5000. You can fix this problem by using a different port for your local host server or turning off the AirPlay Receiver.
To switch off the AirPlay Receiver:
AirPlay Receiver
in the Settings dialog window.If you are using separate frontend and backend repos, you need to configure CORS. To allow cross-origin requests, add the frontend origin to the Access-Control-Allow-Origin
header. In an Express app, you can install the cors
npm
package and add an origin as shown in the code below:
const cors = require("cors"); const corsOptions = { origin: 'http://127.0.0.1:5000', }; app.use(cors(corsOptions));
Your local server may lack file or resource permissions for the current user. In Windows, you can use the following steps to check whether the user running the local web server has the correct permissions to access a folder’s data:
If your access to a port or folder has been blocked by your antivirus software or firewall, you can either use a different port or change your antivirus or firewall settings.
Localhost is the hostname of the IP address that developers use to run a web server on their local computer:
127.0.0.1
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODESConsidered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).
×We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.
Am I included?We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII:
If you have any questions or concerns about your privacy at Sentry, please email us at compliance@sentry.io.
If you are a California resident, see our Supplemental notice.