node.js - nodejs (express) 中的 Auth0 中间件给出错误 : aggrinfo ENOTFOUND

标签 node.js linux express auth0

我在我的 express API 中使用中间件来验证 auth0

const checkJwt = jwt({
    // Dynamically provide a signing key based on the kid in the header and the singing keys provided by the JWKS endpoint.
    secret: jwksRsa.expressJwtSecret({
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
    }),

    // Validate the audience and the issuer.
    audience: process.env.AUTH0_AUDIENCE,
    issuer: `https://${process.env.AUTH0_DOMAIN}/`,
    algorithms: ['RS256']
});

...

  server.use('/api', checkJwt, routes);

它可以在我的本地开发机器上运行,但是当我在生产环境中运行它时,我得到:

Error: getaddrinfo ENOTFOUND undefined undefined:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

我在生产环境中运行 ubuntu 12,在开发环境中运行 mac。

最佳答案

您似乎忘记了在生产系统上设置 AUTH0_DOMAIN 环境变量。

根据 github 中的示例,您的代码是正确的,

但是在这个例子中有一段如何运行这段代码并设置了很多环境变量。

DEBUG=express,jwks JWKS_HOST=https://my-authz-server AUDIENCE=urn:my-resource-server ISSUER=https://my-authz-server/node server.js.

请在启动应用程序之前检查您的生产配置。

关于node.js - nodejs (express) 中的 Auth0 中间件给出错误 : aggrinfo ENOTFOUND,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44438240/

相关文章:

node.js - next.js + expo : You likely forgot to export your component from the file it's defined in, 或者您可能混淆了默认导入和命名导入

node.js - Nodejs - 写入和保存文件

python - 为什么 Ubuntu 系统包会显示 pip freeze/我如何清理 pip freeze?

linux - 如何将变量的输出设置在某一行之上?

javascript - 如何在 Node ,expressjs中的 Elasticsearch 中从 Mongoose 创建索引

javascript - 同步连接到 Node js中的套接字

node.js - 如何在具有 mongoose 数据库的nodejs中存储最新图像

linux - 如何对字符串中的数字使用正则表达式?

javascript - 如何在 node.js 中创建一个 Get 请求以按日期(可以是月、日或年)对请求求和?

javascript - 条件 Jade 模板,用户登录