安装 gem

gem install sinatra
gem install sinatra-jsonp

使用 sinatra/jsonp

require 'sinatra'
require 'sinatra/jsonp'
require 'httpclient'
require 'uri'

set :bind, "0.0.0.0"
set :port, 8080

get '/channel_v3.json' do
  client = HTTPClient.new
  content = client.get_content(URI.encode("https://packagecontrol.io/channel_v3.json"))
  jsonp content
end

此时使用浏览器查看 Content-Type 将可以发现返回的是 Content-Type: application/json 格式的数据.

Comments
Write a Comment