Question

I have a ruby sinatra web service running in centOS on Thin web server. I cannot connect to it remotely with 210.71.253.59:3001/swap. (it does work on localhost), and everything seems to be fine:

-bash-4.1$ ruby spotify_token_swap.rb 
== Sinatra/1.4.5 has taken the stage on 3001 for development with backup from Thin
Thin web server (v1.6.2 codename Doc Brown)
Maximum connections set to 1024
Listening on 210.71.253.59:3001, CTRL+C to stop

I have verified that the 3001 port is open. (I have seen the similar post Ruby Sinatra Webservice running on localhost:4567 but not on IP, still couldn't resolve)

Any ideas to why, or did I do anything wrong? here is mine .rb:

require 'rubygems'
require 'sinatra'
require 'net/http'
require 'net/https'

set :bind, '210.71.253.59'
set :port, 3001

post '/swap' do

    auth_code = params[:code]

    uri = URI.parse("https://ws.spotify.com")
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE

    request = Net::HTTP::Post.new("/oauth/token")
    request.form_data = {
        "grant_type" => "authorization_code",
        "client_id" => kClientId,
        "client_secret" => kClientSecret,
        "redirect_uri" => kClientCallbackURL,
        "code" => auth_code
    }

    response = http.request(request)

    status response.code.to_i
    return response.body

end
Was it helpful?

Solution

Just in case someone arrived at same problem:

it was quite simple... don't forget to check iptables, in my case it was blocking the incoming connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top