Fork me on GitHub
#beginners
<
2016-05-10
>
weller00:05:59

hi guys and gals! total Clojure noob here. i was reading the Brave Clojure book and started using Leiningen. i'm on Windows so used the installer on the Leiningen site, created my project, but getting an error running it: No :main namespace specified in project.clj. my project.clj was created from the lein new app ... command.

weller00:05:29

nevermind, figured it out, thanks anyway! 🦆

bojan.matic03:05:20

@weller: what was the problem?

bwstearns04:05:42

@weller: another thing to keep in mind, when you run lein repl you'll only have things in the namespace as if you were writing code in the body of whatever the :main value points to rather than the whole project (this makes sense after you know the answer and then think about it but can be elusive when you're learning about a bunch of stuff at the same time). I ran into a similar issue and had a comically long workflow for restarting my repl for a bit.

agi_underground15:05:24

hi, port for production jetty server is 80? which port i need to specify in main function?

roberto15:05:40

normally if you want port 80, we proxy through nginx

roberto15:05:13

you can use any port, the risk with running it on port 80 is that you expose yourself to a world of hurt because the process has to be run as root for that to be possible.

roberto15:05:43

it is a common practice when developing jvm-based apps to not use port 80, and proxy through nginx

agi_underground15:05:04

@roberto: yes, when i`m trying to deploy app to heroku with port 80, they stoped with error "permission denied". That means i need to use 8080? Because when i`m not set port in main func. that run jetty server - server stops with error

roberto15:05:32

you can use any port in heroku

roberto15:05:41

it will know to route it to your port

agi_underground15:05:06

this means i can set 3000 port, deploy app, and when i will send the request from browser without specified port, thats will be good?

codefinger15:05:28

you must bind to the port defined by $PORT on Heroku

codefinger15:05:13

you can bind to other ports (above 1028 because those require sudo), but they will not be hooked into the router

agi_underground15:05:28

@codefinger: i can set 3000 port in main func?

roberto15:05:52

yes, but you need to do what @codefinger said, you need to set the $PORT variable in Heroku

agi_underground15:05:35

in heroku in key field i set $PORT and in value field i set 3000 - correct?

agi_underground15:05:34

thank`s for all, i will try yours suggestions

codefinger15:05:46

you can't set $PORT yourself. Heroku assigns it for you. so you have to bind to a port dynamically in the app. For example https://github.com/heroku/clojure-getting-started/blob/master/src/clojure_getting_started/web.clj#L21

agi_underground16:05:03

i was deploy the app with port 5000 in main func, set env variable in heroku to 5000, server was run but when i send request from browser, its give me error in log file, like this - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

codefinger16:05:03

you can't set PORT yourself. You have to use the one Heroku assigns you

codefinger16:05:23

the R10 means nothing bound to the port that Heroku assigned, probably because you are binding to 5000

agi_underground16:05:02

@codefinger: ok, tell me how to write my main func: (defn -main [] (ring/run-jetty #'app {:port 5000}))

codefinger16:05:23

@agi_underground: did you look at the example I linked to above?

codefinger16:05:34

you can use environ and do (env :port) or just (System/getenv "PORT")

agi_underground16:05:14

yes, ok if i connect environ and make like in example, i don`t need to configure manualy in heroku right?

agi_underground16:05:16

i will write about it later, work it or not

codefinger16:05:58

right, you won't ever need (or be able to) configure the port in Heroku

agi_underground20:05:37

with environ all works great! thanx @codefinger