Last active
October 11, 2016 05:39
-
-
Save tanshio/a057459126f503fa64478b5af40d7009 to your computer and use it in GitHub Desktop.
Railsとvue.jsなどのJSフレームワークで、クロスドメイン通信(CORS)の設定をしたい! ref: http://qiita.com/tanshio/items/f35efa7321066d60fc62
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.$http({ | |
params: params, | |
url: URL, | |
method: 'POST', | |
credentials: true | |
}) | |
.then( | |
(response)=> { | |
// success | |
console.log(response); | |
}, | |
(response)=> { | |
// error | |
console.log("error"); | |
console.log(response); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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