【问题标题】:Access to localhost was denied You don't have authorisation to view this page. HTTP ERROR 403访问 localhost 被拒绝 您无权查看此页面。 HTTP 错误 403
【发布时间】:2022-03-27 15:33:09
【问题描述】:

我有一个小型 NodeExpress 服务器,当我尝试向服务器发出请求时,它返回 403 错误 我已经安装了Cors 并使用它并尝试使用 chrome 浏览器和 Postman 作为 2 个客户端并得到相同的拒绝错误

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')
})

【问题讨论】:

    标签: node.js express cors httpclient


    【解决方案1】:

    我在 MacBook Pro (14-inch, 2021), Apple M1 Pro, macOS Monterey 12.3 上使用 firebase serve 时遇到了这个问题

    更新:

    显然原因是

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

    所以the answer quoted above 提出的解决方案是关闭AirPlay Receiver,或者在另一个端口上运行您的应用程序。

    如果您使用 firebase serve 运行您的应用,您可以按照以下方法更改端口:

    source

    firebase.json 文件不适用于 firebase serve 命令。 您必须使用 firebase emulators:start 命令。

    如果你想继续使用 firebase serve 那么它应该像这样使用 在:

    firebase serve --only hosting --port=5002
    

    旧答案:

    答案不够充分,但我可以通过输入 127.0.0.1 而不是 localhost 来绕过这个问题。我不认为这是最好的答案,我也不满意。一旦找到更好的答案,我一定会稍后回来并更新答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-06
      • 2016-03-14
      • 2016-01-31
      相关资源
      最近更新 更多