Heroku返回“;错误:侦听EADDRNOTAVAIL:地址不可用;关于启动Strapi-CMS

Heroku返回“;错误:侦听EADDRNOTAVAIL:地址不可用;关于启动Strapi-CMS,heroku,strapi,heroku-cli,Heroku,Strapi,Heroku Cli,我正试图在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:

我正试图在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。它在本地主机dev和prod环境中都能很好地工作

我的生产文件:

server.js

database.js

response.js

应用程序设置


我在哪里错过了一些东西?

这是
process.env.HOST
的值。由于某种原因与
0.0.0.0
(只是黑暗中的一个镜头-

不同,后者是
process.env.HOST
的值。由于与
0.0.0.0
(只是在黑暗中拍摄)不同的原因,我不得不更改server.js文件(端口443):

My 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
        }
      },
    },
  },
});

我希望它能对有同样问题的人有所帮助:-)

我必须更改server.js文件(端口443):

My 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
        }
      },
    },
  },
});

我希望它能对有同样问题的人有所帮助:-)

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


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

不确定这是否是@Rochadsouza的意思,但我得到了相同的错误,最终解决问题的方法是将主机设置为
0.0.0
。由于某些原因,主机不能是应用程序url,它需要允许Heroku上的所有主机。我正在使用
env('host','0.0.0.0')
server.js
中设置主机,但是在Heroku上将
host
env变量设置为我的应用程序url


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

您解决了吗?我也面临着同样的问题。嗨@Touha,我刚刚回答了我的问题。:)你解决了吗?我也面临着同样的问题。嗨@Touha,我刚刚回答了我的问题。:)我不明白这怎么能解决你的问题。Heroku将始终根据为您的应用程序选择的端口定义端口env var(如果我查看您得到的错误,端口
31639
)。这意味着,如果使用
env.int('PORT',443)
定义主机,将使用Heroku定义的端口env var,而不是443。可能解决这个问题的是,你的主机现在是一个整数,但它过去是一个字符串。我不明白这怎么能解决你的问题。Heroku将始终根据为您的应用程序选择的端口定义端口env var(如果我查看您得到的错误,端口
31639
)。这意味着,如果使用
env.int('PORT',443)
定义主机,将使用Heroku定义的端口env var,而不是443。可能解决这个问题的是,您的主机现在是一个整数,但它过去是一个字符串。