Comments (7)
@iamkdev try adding this code to application.rb
:
config.middleware.insert_before 3, 'Rack::Cors', debug: true, logger: (-> { Rails.logger }) do
allow do
origins ENV['CLIENT_ROOT_URL'] # in your case would want equal to http://localhost:8000
resource '/api/*',
headers: :any,
methods: %i[get post delete put patch options head]
end
end
from rails-realworld-example-app.
Thanks @ahcarpenter. It works.
from rails-realworld-example-app.
@iamkdev welcome!
from rails-realworld-example-app.
Seems it's not fixed. I checkedout to Rails 5.1 Branch and It does'nt working.
from rails-realworld-example-app.
As per above Comment origins ENV['CLIENT_ROOT_URL']
reference which is now
origins Rails.application.secrets[:client_root_url]
in environment.
To make it working One should update client_root_url
in secrets YAML depending upon React/FrontEnd App Port.
For Example, if my React/FrontEnd app Port is 4000 then client_root_url
should be http://localhost:4100
Please consider this issue Closed (as it already). This comment is for Other People like me.
from rails-realworld-example-app.
Thanks @rajeevkannav.
from rails-realworld-example-app.
I'm still having the same problem with localhost an angular4
environment.ts
export const environment = {
production: false,
api_url: 'http://localhost:4201/api'
};
secrets.yml
shared:
client_root_url: http://localhost:4201
application.rb
# frozen_string_literal: true
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Conduit
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
config.api_only = true
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.middleware.insert_before 0, Rack::Cors, debug: true, logger: (-> { Rails.logger }) do
allow do
origins Rails.application.secrets[:client_root_url]
resource '/api/*',
headers: :any,
methods: %i[get post delete put patch options head]
end
end
end
end
rails server
rails s -p 4201
Thank you!
from rails-realworld-example-app.
Related Issues (10)
- Cannot Register HOT 1
- fatal: repository 'https://github.com/gogovan/devise.git/' not found HOT 5
- Failures when testing against the Realworld API Spec
- rake aborted! NoMethodError: undefined method 'new' for BigDecimal:Class
- `json` v 1.8.3 won't install HOT 1
- Convert to API-only app
- Use ActiveModel::Serializers HOT 1
- Add Rubocop
- Upgrade to Rails 5 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails-realworld-example-app.