LoginSignup
2
2

More than 5 years have passed since last update.

WEBrickでCORS

Last updated at Posted at 2017-03-27
  • サーバーインスタンス生成時のオプションに、レスポンスヘッダーにCORSのヘッダーを出力するように指定
    • * ですべてのドメインを許可
    • 下記ではポート3000を指定
ruby -rwebrick -e "WEBrick::HTTPServer.new( DocumentRoot: '.', Port: 3000, RequestCallback: Proc.new{|req,res| res['Access-Control-Allow-Origin'] = '*' } ).start"
  • ユースケース
    • revealjsを使っていて、xxxx.mdのデータをajaxで雑に取得したかった。ローカルでnginxを起動する、nodejsでserve -Cするなど考えたが、普段Rubyをよく使うのでこれが導入しやすかった。
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2