serve icon indicating copy to clipboard operation
serve copied to clipboard

Can't start serve on a different port

Open joevandyk opened this issue 14 years ago • 9 comments

$ serve 2100
[2011-09-05 13:43:36] INFO  WEBrick 1.3.1
[2011-09-05 13:43:36] INFO  ruby 1.9.2 (2011-07-09) [x86_64-darwin11.1.0]
[2011-09-05 13:43:36] INFO  WEBrick::HTTPServer#start: pid=40613 port=4000

It's running on port 4000, I'd expect it to use port 2100.

joevandyk avatar Sep 05 '11 20:09 joevandyk

Bah, figured it out.

I had to remove this line from the generated config.ru:

#\ -p 4000

joevandyk avatar Sep 05 '11 20:09 joevandyk

Is there a reason why that line is there?

joevandyk avatar Sep 05 '11 20:09 joevandyk

In this case Serve is just delegating to the rackup command. You need to edit your config.ru. The very first line tells it which port to start.

John Long http://wiseheartdesign.com

On Sep 5, 2011, at 4:47 PM, [email protected] wrote:

$ serve 2100 [2011-09-05 13:43:36] INFO WEBrick 1.3.1 [2011-09-05 13:43:36] INFO ruby 1.9.2 (2011-07-09) [x86_64-darwin11.1.0] [2011-09-05 13:43:36] INFO WEBrick::HTTPServer#start: pid=40613 port=4000 ^C[2011-09-05 13:43:38] INFO going to shutdown ... [2011-09-05 13:43:38] INFO WEBrick::HTTPServer#start done.

Reply to this email directly or view it on GitHub: https://github.com/jlong/serve/issues/49

jlong avatar Sep 06 '11 03:09 jlong

Right, but why is is this line here?

https://github.com/jlong/serve/blob/master/lib/serve/bootstrap/config.ru#L1

Everyone who wants to run serve on a different port will need to know to remove that line if they want to follow the documentation in the README.

joevandyk avatar Sep 06 '11 04:09 joevandyk

Well, the assumption here is that if you have a project with a config.ru in it that you know which port you want it to run on, so if you want to change it, you'd change it in the config.ru. But perhaps the -p option should override as you suggest. In fact, I'm leaning that way now that you've talked me through it.

This month is kind of busy for me so I don't have a lot of time to work on Serve, but I'd merge a pull request if you send one my way. It's probably just a matter of making sure the port is handed over to the rackup command in the Application object.

Otherwise, it'll be a bit before I get to it.

--John

On Sep 6, 2011, at 12:29 AM, joevandyk wrote:

Right, but why is is this line here?

https://github.com/jlong/serve/blob/master/lib/serve/bootstrap/config.ru#L1

Everyone who wants to run serve on a different port will need to know to remove that line if they want to follow the documentation in the README.

Reply to this email directly or view it on GitHub: https://github.com/jlong/serve/issues/49#issuecomment-2008785

jlong avatar Sep 06 '11 14:09 jlong

This looks like it might be in the rackup command itself. You're passing the user-supplied port in Serve::Application#run_rack_app, and trying rackup -p 2100 -o 0.0.0.0 -E development './config.ru' in the command line exhibits the behavior of using the port from config.ru rather than from the -p argument.

$ rackup -p 2100 -o 0.0.0.0 -E development './config.ru'
[2011-09-12 19:39:13] INFO  WEBrick 1.3.1
[2011-09-12 19:39:13] INFO  ruby 1.9.2 (2011-07-09) [x86_64-darwin10.8.0]
[2011-09-12 19:39:13] INFO  WEBrick::HTTPServer#start: pid=9125 port=4000

pbyrne avatar Sep 13 '11 00:09 pbyrne

Even when I change #\ 4100 and run bundle exec serve I see:

$> ps aux|grep -i rackup
hedge    19696  6.4  0.2 128644 47228 pts/30   Sl   19:59   0:08 ruby /src/proj/vendor/ruby/1.9.1/bin/rackup -p 3000 │Using /home/hedge/.rvm/gems/ruby-1.9.2-p290 with gem-o 0.0.0.0 -E development ./config.ru

hedgehog avatar Nov 21 '11 09:11 hedgehog

So what's the verdict? Should we remove the port from the config.ru? Honestly it seems really strange to me to have it hardcoded in there.

ntalbott avatar Apr 06 '12 14:04 ntalbott

Yes. I still want the rails_app? checks in there though. That stuff should be updated for Rails 3 though. The idea is that serve can be used to start any rack or rails app, too.

jlong avatar Apr 06 '12 14:04 jlong