编程语言
首页 > 编程语言> > node.js – nodejs(express)中的Auth0中间件给出错误:aggrinfo ENOTFOUND

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

作者:互联网

我在我的快速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,在dev上运行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.

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

标签:linux,node-js,express,auth0
来源: https://codeday.me/bug/20190608/1196847.html