我试图在Heroku的Cedar堆栈上运行Compojure / Ring应用程序(但失败了)。我遵循了这些指南
首先,我部署了B),然后似乎成功地启动了网络dyno C)。但是在访问我的应用程序的URL时,我什么都没看到。运行heroku ps会显示正在运行的进程,但我无法从Web访问我的应用程序。有什么特别的我不见了?我需要使用git的master分支吗?如果我在我的Procfile中使用lein run(我已经尝试了几个命令),Heroku(或工头)如何知道要运行哪个http处理程序(同样是Compojure / Ring应用程序)?
B)
$ git push heroku Counting objects: 4, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 293 bytes, done. Total 3 (delta 1), reused 0 (delta 0) To git@heroku.com:high-night-9597.git 36e7c18..050ea6d account-chooser ->
C)
$ heroku ps:scale web=1 Scaling web processes... done, now running 1
D)
$ heroku ps Process State Command ------- ---------------- --------- run.1 complete for 11m lein repl web.1 created for 8m
E)
$ heroku run lein repl Running lein repl attached to terminal... up, run.1
F) Procfile:
-web: lein exec src/.clj +web: lein run
答案 0 :(得分:2)
您可以使用您喜欢的任何分支,但是如果您不在该分支中,则需要指定要推送到heroku的分支:
$ git push heroku your_branch_name
如果您的应用程序在本地运行正常,Heroku知道如何根据您在Procfile中的内容运行它,在您的情况下似乎缺少某些内容。
假设您的主要处理程序位于$YOUR_APP_ROOT/src/my-clj-app/core.clj
。
然后,您的Procfile应该看起来像这样:
web: lein run -m my-clj-app.core
Heroku知道如何运行你的应用程序。
确保该文件具有正确的命名空间定义:
(ns my-clj-app.core)
你可以尝试一下吗?
答案 1 :(得分:1)
我也是新人,但我会尝试分享我遇到的一些问题 如果是您怀疑的端口错误,您是否正确设置了端口?
(ns demo.web
(:use ring.adapter.jetty))
(defn app [req]
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Hello, world"})
(defn -main []
(let [port (Integer/parseInt (System/getenv "PORT"))]
(run-jetty app {:port port})))
我将列出我遇到的一些问题,也许它可能对你有帮助。
Procfile应如下所示:
web: lein run -m http.handler
而不是
'web: lein run -m http.handler'
如果正确检测到Procfile,您应该看到:
Heroku输出
-----> Discovering process types
Procfile declares types -> web ;; <- This line should appear
-----> Compiled slug size is 14.2MB
-----> Launching... done, v15
在我开始使用web dyno之前,当我运行lein repl
时,我也发现了一个问题(错误?)。你应该先尝试关闭你的“repl”:
heroku ps:stop run.1
然后运行web dyno:
heroku ps:scale web=1.
如果你不小心关闭了你的网络动态:
heroku ps:scale web=0
Heroku不会在您下次推送到Heroku时自动启动网络dyno。因此,在提交heroku之前,请检查是否有web dyno正在运行。您也可以在提交后启动Web dyno。
对我来说,我能够成功地遵循这个写得很好的教程 - http://thecomputersarewinning.com/post/clojure-heroku-noir-mongo。
如果您使用的是Noir 1.2.2,则需要删除:
(:require [myapp.views.noir.content.getting-started] :as content)
来自“welcome.clj”。
答案 2 :(得分:0)
这是一个后续问题。正如在abouve评论中所概述的那样,我能够将我的应用程序推送到Heroku的主人,然后部署它。
但是当我尝试转到我应用的网址时,我收到以下错误。这是一个奇怪的端口错误,但我不认为我在Heroku上部署Clojure应用程序时可以控制这些细节。我认为我的设置很简单。有什么办法可以解决这个错误吗?
<强> Procfile 强>
web: lein run -m http.handler
<强> http.handler 强>
... (def app (handler/site main))
错误强>
2011-12-31T04:10:02+00:00 app[web.1]: Listening for transport dt_socket at address: 41208 2011-12-31T04:10:03+00:00 heroku[web.1]: Stopping process with SIGKILL 2011-12-31T04:10:03+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 41208, should be 55032 (see environment variable PORT) 2011-12-31T04:10:04+00:00 heroku[web.1]: State changed from starting to crashed 2011-12-31T04:10:05+00:00 heroku[web.1]: Process exited 2011-12-31T04:20:08+00:00 heroku[web.1]: State changed from crashed to created 2011-12-31T04:20:08+00:00 heroku[web.1]: State changed from created to starting 2011-12-31T04:20:12+00:00 heroku[web.1]: Starting process with command `lein run -m http.handler` 2011-12-31T04:20:16+00:00 app[web.1]: Listening for transport dt_socket at address: 49151 2011-12-31T04:20:16+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 49151, should be 39092 (see environment variable PORT) 2011-12-31T04:20:16+00:00 heroku[web.1]: Stopping process with SIGKILL 2011-12-31T04:20:17+00:00 heroku[web.1]: State changed from starting to crashed 2011-12-31T04:20:18+00:00 heroku[web.1]: Process exited 2011-12-31T04:31:13+00:00 heroku[web.1]: State changed from crashed to created 2011-12-31T04:31:13+00:00 heroku[web.1]: State changed from created to starting 2011-12-31T04:31:16+00:00 heroku[web.1]: Starting process with command `lein run -m http.handler` 2011-12-31T04:31:20+00:00 app[web.1]: Listening for transport dt_socket at address: 44321 2011-12-31T04:31:20+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 44321, should be 17211 (see environment variable PORT) 2011-12-31T04:31:20+00:00 heroku[web.1]: Stopping process with SIGKILL 2011-12-31T04:31:22+00:00 heroku[web.1]: State changed from starting to crashed 2011-12-31T04:31:22+00:00 heroku[web.1]: Process exited 2011-12-31T04:44:59+00:00 heroku[web.1]: State changed from crashed to created 2011-12-31T04:44:59+00:00 heroku[web.1]: State changed from created to starting 2011-12-31T04:45:02+00:00 heroku[web.1]: Starting process with command `lein run -m http.handler` 2011-12-31T04:45:05+00:00 app[web.1]: Listening for transport dt_socket at address: 37500 2011-12-31T04:45:06+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 37500, should be 14046 (see environment variable PORT) 2011-12-31T04:45:06+00:00 heroku[web.1]: Stopping process with SIGKILL 2011-12-31T04:45:07+00:00 heroku[web.1]: State changed from starting to crashed 2011-12-31T04:45:07+00:00 heroku[web.1]: Process exited 2011-12-31T04:49:22+00:00 heroku[router]: Error H10 (App crashed) -> GET bkeeping.herokuapp.com/ dyno= queue= wait= service= status=503 bytes= 2011-12-31T04:49:31+00:00 heroku[router]: Error H10 (App crashed) -> GET bkeeping.herokuapp.com/favicon.ico dyno= queue= wait= service= status=503 bytes=