Skip to content

Instantly share code, notes, and snippets.

@tanshio
Last active October 11, 2016 05:39
Show Gist options
  • Save tanshio/a057459126f503fa64478b5af40d7009 to your computer and use it in GitHub Desktop.
Save tanshio/a057459126f503fa64478b5af40d7009 to your computer and use it in GitHub Desktop.
Railsとvue.jsなどのJSフレームワークで、クロスドメイン通信(CORS)の設定をしたい! ref: http://qiita.com/tanshio/items/f35efa7321066d60fc62
# developmentモードの時だけCORSを有効にする
if Rails.env.development?
config.middleware.insert_before ActionDispatch::Static, Rack::Cors do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options, :patch, :delete]
end
end
end
this.$http({
params: params,
url: URL,
method: 'POST',
credentials: true
})
.then(
(response)=> {
// success
console.log(response);
},
(response)=> {
// error
console.log("error");
console.log(response);
}
);
group :development, :test do
gem 'rack-cors', :require => 'rack/cors'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment