【问题标题】:Heroku returns "Error: listen EADDRNOTAVAIL: address not available" on starting Strapi CMSHeroku 在启动 Strapi CMS 时返回“错误:监听 EADDRNOTAVAIL:地址不可用”
【发布时间】:2020-09-14 16:54:10
【问题描述】:

我正在尝试在 Heroku 上部署 Strapi

但它不起作用。我得到了这个日志

2020-05-27T15:04:05.012958+00:00 app[web.1]: > strapi-oskogen-mongodb@0.1.0 start /app
2020-05-27T15:04:05.012959+00:00 app[web.1]: > node server.js
2020-05-27T15:04:05.012960+00:00 app[web.1]: 
2020-05-27T15:04:08.188595+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
2020-05-27T15:04:08.188639+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2020-05-27T15:04:08.189164+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
2020-05-27T15:04:08.189299+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
2020-05-27T15:04:08.189381+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
2020-05-27T15:04:12.308848+00:00 app[web.1]: [2020-05-27T15:04:12.308Z] error Error: listen EADDRNOTAVAIL: address not available 52.54.48.43:31639
2020-05-27T15:04:12.308857+00:00 app[web.1]:     at Server.setupListenHandle [as _listen2] (net.js:1296:21)
2020-05-27T15:04:12.308858+00:00 app[web.1]:     at listenInCluster (net.js:1361:12)
2020-05-27T15:04:12.308859+00:00 app[web.1]:     at GetAddrInfoReqWrap.doListen [as callback] (net.js:1498:7)
2020-05-27T15:04:12.308859+00:00 app[web.1]:     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:68:8)
2020-05-27T15:04:22.927720+00:00 heroku[web.1]: Stopping all processes with SIGTERM

我在 Atlas 上使用 MongoDB。它在本地主机上运行良好,无论是开发环境还是生产环境。

我的生产文件:

server.js

database.js

response.js

应用设置

我错过了什么?

【问题讨论】:

  • 你解决了吗?我也面临同样的问题。
  • 嗨@Touha 我刚刚回答了我的问题。 :)

标签: heroku strapi heroku-cli


【解决方案1】:

这是process.env.HOST 的值。由于某种原因与0.0.0.0 不同(只是在黑暗中拍摄 - https://strapi.io/documentation/3.0.0-beta.x/migration-guide/migration-guide-beta.19-to-beta.19.4.html#listened-host-changed)

【讨论】:

    【解决方案2】:

    我不得不更改 server.js 文件(端口 443):

    module.exports = ({ env }) => ({
      host: env('HOST', '0.0.0.0'),
      port: env.int('PORT', 443),
      admin: {
        auth: {
          secret: env('ADMIN_JWT_SECRET'),
        },
      },
    });
    

    我的 database.js 文件:

    module.exports = ({ env }) => ({
      defaultConnection: "default",
      connections: {
        default: {
          connector: "mongoose",
          settings: {
            uri: env("DATABASE_URI"),
            ssl: { rejectUnauthorized: false }
          },
          options: {
            ssl: true,
            authenticationDatabase: "",
            useUnifiedTopology: true,
            pool: {
              min: 0,
              max: 10,
              idleTimeoutMillis: 30000,
              createTimeoutMillis: 30000,
              acquireTimeoutMillis: 30000
            }
          },
        },
      },
    });
    

    希望对遇到同样问题的人有所帮助:-)

    【讨论】:

    • 我不明白这如何解决您的问题。 Heroku 将始终根据为您的应用程序选择的端口(端口31639,如果我查看您收到的错误)定义 PORT env var。这意味着如果您使用env.int('PORT', 443) 定义您的主机,则将使用 Heroku 定义的 PORT env var,而不是 443。可能解决的问题是您的主机现在是一个整数,但它曾经是一个字符串。
    【解决方案3】:

    不确定这是否是@Rochadsouza 的意思,但我遇到了同样的错误,在我的情况下最终解决的问题是将主机设置为0.0.0.0。由于某些原因,host 不能是应用程序的 url,它需要允许 Heroku 上的所有主机。我正在使用env('HOST', '0.0.0.0') 将主机设置为server.js,但在Heroku 上将HOST env var 设置为我的应用程序网址...

    希望它可以为面临相同错误的其他人节省一些时间。

    【讨论】:

      猜你喜欢
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      • 2017-10-12
      • 1970-01-01
      • 2021-02-11
      • 2020-11-09
      • 2020-04-08
      相关资源
      最近更新 更多