Search code examples
rubysinatracloud9-ide

Error while running Sinatra app on Cloud 9


I am using cloud 9 IDE to follow this tutorial. How can I run Sinatra on Cloud 9 ? I created a blank workspace in cloud 9, ran gem install from command line. But running Sinatra from command line doesn't work. I notice it flags Important: use ENV[PORT] as the port and ENV[IP] as the host in your scripts! after starting the server. How can I make this work? Thank you in advance.


Solution

  • As the c9 window says "...; make sure it's on port $PORT with $IP as the IP address", this is, don't replace $PORT or $IP with your own values, they're values already defined, you can check it using echo $IP && echo $PORT.

    Try running ruby hi.rb -p $PORT -o $IP within your Sinatra project directory.

    You can also define the port and ip as environment variables as the flags you noticed say running the export PORT=<port> && export IP=<ip> command, and then access to them within any ruby file as ENV['PORT'] or ENV['IP'].

    Note: For some reason when I use the route get '/hi' it didn't work running on c9.io, but it did it correctly in my local machine, if you have the same mistake try just get '/'.