:-O 
That just blew my mind - Thanks! :)

On Friday, December 23, 2016 at 11:01:28 AM UTC-5, James Reeves wrote:
>
> I think this is something a lot of web developers take for granted, so 
> perhaps it isn't mentioned as much as it could be.
>
> The usual convention in Linux environments is to set the port via the PORT 
> environment variable. So on the command line it would be:
>
>   PORT=3001 java -jar yourapp.jar
>
> That's what this line does in your source code:
>
> (Integer/parseInt (or (env :port) "3000"))
>
> It looks for the "PORT" environment variable, and if it doesn't find it 
> then it defaults to "3000". Then it converts the resulting string into an 
> integer.
>
> You may want to take a look at the Luminus deployment guide 
> <http://www.luminusweb.net/docs/deployment.md>. Luminus is a commonly 
> used project template, but the deployment docs apply to most Clojure web 
> projects and cover a range of setups.
>
> - James
>
>
> On 23 December 2016 at 14:11, Seth Archambault <seth...@gmail.com 
> <javascript:>> wrote:
>
>> I'm posting this because right now someone is scrounging the internet for 
>> 3 hours to find this simple solution, I hope that they find this post 
>> sooner rather than later, and can move on to their next project!
>>
>> *TLDR*
>>
>> Goto /src/clj/myapp/server.clj
>>
>> Edit "3000" to be whatever you want:
>>
>>  (defn -main [& args]
>>    (let [port (Integer/parseInt (or (env :port) "3000"))]
>>      (run-jetty app {:port port :join? false})))
>>
>> Now Here's the journey of a new user to find this information...
>>
>> Let's say you installed Clojure with:
>>
>> lein new reagent myapp
>>
>> You built out your app, and everything went well! Time to deploy.
>>
>> You may have stumbled upon this DigitalOcean guide, How To Deploy a 
>> Clojure Web Application on Ubuntu 14.04 
>> <https://www.digitalocean.com/community/tutorials/how-to-deploy-a-clojure-web-application-on-ubuntu-14-04>
>>
>> It worked mostly, though your app wants to run on port 3000, not 5000. No 
>> problem, just changed it in the nginx config
>>
>>     6 server { 
>>   7     listen 80;
>>   8     server_name www.myapp.us myapp.us;
>>   9     location / {
>>  10         proxy_pass http://127.0.0.1:3000;
>>  11         proxy_http_version 1.1;
>>  12         proxy_set_header Connection "";
>>  13         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
>>  14         proxy_set_header Host $http_host;
>>  15         access_log /var/www/myapp/logs/myapp.access.log;
>>  16         error_log /var/www/myapp/logs/myapp.error.log;
>>  17     }
>>  18 }
>>
>> The recommended /etc/supervisor/conf.d/myapp.conf file worked great. Your 
>> site is launched and all is well!
>>
>> Okay so with that resounding success you decide you want to launch a 
>> second clojure app. 
>>
>> First, if you're used to using php and nginx, you might be thinking you 
>> may be able to have your app run on the default port buy "look" for another 
>> url, maybe it's something you can easily change in the nginx config, or the 
>> supervisor config, or maybe the project.clj file. But a search on google 
>> seems to be focused on using separate port numbers:
>>
>> How can I run multiple Ring apps on the same server? 
>> <http://stackoverflow.com/questions/15732618/how-can-i-run-multiple-ring-apps-on-the-same-server>
>>  
>>
>> You don't necessarily think of your app as a "Ring" app - sure it's a 
>> library, but isn't this just Clojure? Anyways, this seems to be the 
>> solution, but how do we change the port? 
>>
>> Searching google some more:
>>
>> Offical Lein Ring Instructions <https://github.com/weavejester/lein-ring> - 
>> not helpful
>> How to set ring port based on profile 
>> <http://stackoverflow.com/questions/27945399/how-to-set-ring-port-based-on-profile>
>>  - 
>> something about profiles, not helpful 
>> You browser the rest of the front page of google and continue to get 
>> posts like this.
>>
>> If you come from a mainstream language like PHP, you're thinking "Hmm, 
>> deploying multiple apps is an extremely basic task.. Why do I feel like I'm 
>> the first one to ever do it?"
>>
>> Thinking that maybe it's just a standard Java thing, you start searching 
>> for "change java jar port". But these all yeild posts that recommend 
>> changing the port via commands like this:
>>
>> java -jar jenkins.war --httpPort=9090 
>>
>> None of these will works, but you will have to wait 60 seconds after 
>> typing it in each time to find out.  
>> Hours have passed. For the first time in your life as a programmer, 
>> Google has actually failed you.You are all alone now.
>>
>> Finally, you open the project in an editor you're experienced with - 
>> Sublime text - and search the whole project for port. 
>>
>> You find the place to change the port at /src/clj/myapp/server.clj ! 
>>
>> You are victorious, but you feel let down by Google, and frustrated that 
>> the solution was random flailing around.
>>
>> *Epilogue*
>>
>> I really love Clojure. This is the first time, in a bout 10 years I've 
>> been this excited about programming. Functional, lisp-like programming 
>> feels like an absolute revolution to someone who has only ever experienced, 
>> php, ruby, python, and javascript.
>>
>> However, early on in my Clojure journey I've encountered two extremely 
>> basic problems where the solutions simply don't seem to be findable on 
>> Google! There really is this feeling like, am I the first person to have 
>> eve encountered this problem? Am I the only one who is coming to Clojure 
>> from building web apps using Laravel (An excellent framework, unfortunately 
>> written in php)
>>
>> Maybe there aren't a whole lot of beginners, or maybe some of the 
>> beginner written material no longer applies to the new fancy ways to get 
>> started. This is concerning. As a newby I want to be able to jump in 
>> knowing that the foundation has already been built. As nice as it is to use 
>> a command like "lein new reagent myapp" - I don't want to do that if the 
>> result is I get a tree of code made for me that most of the community 
>> hasn't used yet. What's frustrating is that this folder structure isn't 
>> explicitly connected to the project.clj - like there's no way you could 
>> study the project.clj and determine that /src/clj/myapp/server.clj is 
>> used by anything. It just happens magicaly, the complexity is hidden...
>>
>> Again, I'm really enjoying clojure so far, and I really agree with the 
>> creators vision, but I'm concerned whenever really easy tasks take forever 
>> to do and seem to have hidden complexity.
>>
>> I'm interested in other peoples thoughts here. Have you felt in a similar 
>> way? What am I doing wrong? 
>>
>> Thanks!
>> Seth
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> <javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to