Я использую Ruby on Rails 5 в качестве backend и Angular 5 в качестве frontend. Я запускаю приложение на localhost для тестирования. И проблема в том, что Rails время от времени зависает. И из-за этого Angular перестает отображать информацию. И чтобы возобновить работу Rails приходится перезапускать процесс. Но для перезагрузки нужно сначала убить процесс, а затем снова запустить.
Из-за этого возникает такая ошибка:
GET localhost:3000/users 504 (Gateway Time-out)
Failed to load localhost:3000/users: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:4200' is therefore not allowed access. The response had HTTP status code 504.
Как это исправить?
cors.rb:
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '127.0.0.1:4200', 'localhost:4200'
resource '*',
:headers => :any,
:expose => ['access-token', 'expiry', 'token-type', 'uid', 'client'],
:methods => [:get, :post, :options, :delete, :put]
end
end
database.yml:
default: &default
adapter: oracle_enhanced
database: ********************************************
username: **********
password: **********
development:
<<: *default
database: ********************************************
username: **********
password: **********
test:
<<: *default
production:
<<: *default
gemfile:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.6'
# Use sqlite3 as the database for Active Record
gem 'ruby-oci8'
gem 'activerecord-oracle_enhanced-adapter'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem 'rack-cors'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'omniauth'
gem 'devise_token_auth'
gem 'devise-i18n'
gem 'logs'
gem 'logstasher'
group :development do
gem 'capistrano', require: false
gem 'capistrano-rvm', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano3-puma', require: false
end
Если нужно что-то еще докинуть напишите.