オンラインデータのクロスオリジンプロキシdejimaの作成
前回のleaflet-omnivoreの検証で気がついたことは、オンラインデータについて、フォーマットの問題はクライアントサイドで片付きつつあるのに対して、クロスドメイン問題は、CORS設定の普及が間に合っていないという問題である。この問題を当面回避するために、CORS設定をonにして中継するだけのサーバをherokuに書いてみた。
URL及び動作例
URL は http://dejima.herokuapp.com/?url=<URL> である。例えば、http://dejima.herokuapp.com/?url=https://raw.githubusercontent.com/shimizu/dataSet/master/fukui_kindergarten/fukui_kindergarten.geojson といった中継をさせていただくことができる。
プログラム
app.rb
非常に大雑把なプログラムだ。
require 'bundler/setup' require 'sinatra/base' require 'open-uri' class App < Sinatra::Base get '/' do begin open(params['url']) do |input| content_type input.content_type headers 'Access-Control-Allow-Origin' => '*' input.read end rescue status 500 "don't steal data." end end end
config.ru
$:.unshift(File.dirname(__FILE__)) require 'app' run App
Gemfile
source "https://rubygems.org" gem "sinatra"
Procfile
web: bundle exec rackup config.ru -p $PORT