这是我在 Parse-Server (/Heroku) 上的应用程序遇到的问题。
我不断收到消息:
WARNING, Unable to connect to 'https://myapp.herokuapp.com/'. Cloud code and push notifications may be unavailable!
这是我运行命令时的完整日志:git push heroku master
2018-02-2...+00:00 app[api]: Build started by user <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e636b4e767774206d6163" rel="noreferrer noopener nofollow">[email protected]</a>
2018-02-2...+00:00 app[api]: Deploy bduxedc8 by user <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ee3ebcef6f7f4a0ede1e3" rel="noreferrer noopener nofollow">[email protected]</a>
2018-02-2...+00:00 app[api]: Build succeeded
2018-02-2...+00:00 app[api]: Release v25 created by user <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5c8c0e5dddcdf8bc6cac8" rel="noreferrer noopener nofollow">[email protected]</a>
2018-02-2...+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-2...+00:00 heroku[web.1]: Process exited with status 143
2018-02-2...+00:00 heroku[web.1]: Restarting
2018-02-2...+00:00 heroku[web.1]: State changed from up to starting
2018-02-2...+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-2...+00:00 app[web.1]:
2018-02-2...+00:00 app[web.1]: > <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f3f2e3d3c2a623c2a3d392a3d622a372e223f232a0f7e617b617f" rel="noreferrer noopener nofollow">[email protected]</a> start /app
2018-02-2...+00:00 app[web.1]: > node index.js
2018-02-2...+00:00 app[web.1]:
2018-02-2...+00:00 app[web.1]: parse-server-example running on port 23377.
2018-02-2...+00:00 heroku[web.1]: State changed from starting to up
2018-02-2...+00:00 heroku[router]: at=info method=GET path="/health" host=myapp.herokuapp.com request_id=fb429287-9b14-4373-97ab-30dac19a4db7 fwd="1.2.3.438" dyno=web.1 connect=2ms service=20ms status=404 bytes=217 protocol=https
2018-02-28T04:03:21.595649+00:00 app[web.1]:
2018-02-28T04:03:21.595660+00:00 app[web.1]: WARNING, Unable to connect to 'https://myapp.herokuapp.com/'. Cloud code and push notifications may be unavailable!
2018-02-28T04:03:21.595663+00:00 app[web.1]:
如果我在配置中将 https
更改为 http
,我会看到完全相同的行为。
此外,如果我尝试访问 https://myapp.herokuapp.com/在浏览器中我可以毫无问题地做到这一点。
我读过很多关于这个问题的文章,但没有什么促使我找到解决方案。 如果有人能让我知道如何解决这个问题,那就太好了。
最佳答案
我遇到了这个问题,它可能会对将来的某人有所帮助。
请注意,这是可能引发此警告的原因之一。 这是解析服务器版本:2.8.2
要使用express创建您自己的独立解析服务器,所涉及的基本步骤接近于:
- 使用您的所有配置创建一个解析服务器对象。例如:const api = new ParseServer(config);
- config 将包含服务器 URL 以及所有其他要求。
- 创建一个 Express 应用对象。例如:const app = express();
- 然后在 Express 上挂载解析服务器 API,例如 -> app.use(mountPath, api);
- 然后创建服务器,如下所示: const httpServer = require('http').createServer(app);
- 然后开始监听端口,例如:httpServer.listen(port);
一旦调用挂载,解析服务器将通过向/health 端点发出请求来验证配置中提到的 url。
如果由于某种原因在挂载 API(第 4 点)后监听端口(第 6 点)出现延迟,则会抛出上述警告。
例如,在一种情况下,我正在建立 Mongoose 连接,然后才开始监听端口。因此,解析服务器对 URL 的验证失败,尽管此后一切正常。
可能的解决方案之一是在安装解析 API 之前完成所有此类工作,并确保安装和监听端口之间没有延迟,如上所述。
虽然这可能不是在 heroku 上创建解析服务器的确切步骤,但其想法是:
解析服务器将在配置中提到的服务器 url 上调用验证 url。
如果在解析 API 后启动服务器出现延迟,则会抛出上述警告。
关于node.js - 云代码和推送通知可能不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49022089/