Farmbot-Web-App/config/application.rb

108 lines
4.2 KiB
Ruby
Raw Normal View History

require_relative "../app/models/transport.rb"
2014-03-12 07:42:11 -06:00
require File.expand_path('../boot', __FILE__)
require "rails/all"
2014-03-12 07:42:11 -06:00
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module FarmBot
2014-03-12 07:42:11 -06:00
class Application < Rails::Application
2017-11-09 09:45:11 -07:00
config.active_job.queue_adapter = :delayed_job
2016-05-09 09:08:42 -06:00
config.action_dispatch.perform_deep_munge = false
2014-05-22 07:42:45 -06:00
I18n.enforce_available_locales = false
2014-05-08 08:02:51 -06:00
config.generators do |g|
2016-12-01 11:50:07 -07:00
g.template_engine :erb
2017-10-22 07:19:50 -06:00
g.test_framework :rspec, :fixture_replacement => :factory_bot, :views => false, :helper => false
2014-05-08 08:02:51 -06:00
g.view_specs false
g.helper_specs false
2017-10-22 07:19:50 -06:00
g.fixture_replacement :factory_bot, :dir => 'spec/factories'
2014-05-08 08:02:51 -06:00
end
config.autoload_paths << Rails.root.join('lib')
config.autoload_paths << Rails.root.join('lib/sequence_migrations')
2016-11-23 11:40:22 -07:00
config.middleware.insert_before ActionDispatch::Static, Rack::Cors do
2015-10-20 13:25:08 -06:00
allow do
origins '*'
resource '/api/*',
headers: :any,
methods: [:get, :post, :delete, :put, :patch, :options, :head],
expose: "X-Farmbot-Rpc-Id",
2015-10-20 13:25:08 -06:00
credentials: false, # No cookies.
max_age: 0
end
end
Rails.application.routes.default_url_options[:host] = ENV["API_HOST"] || "localhost"
2017-07-06 14:04:13 -06:00
Rails.application.routes.default_url_options[:port] = ENV["API_PORT"] || 3000
2016-11-08 15:09:46 -07:00
# ¯\_(ツ)_/¯
$API_URL = "//#{ Rails.application.routes.default_url_options[:host] }:#{ Rails.application.routes.default_url_options[:port] }"
2018-01-13 09:39:43 -07:00
ALL_LOCAL_URIS = (
[ENV["API_HOST"]] + (ENV["EXTRA_DOMAINS"] || "").split(",")
)
.map { |x| x.present? ? "#{x}:#{ENV["API_PORT"]}" : nil }.compact
SecureHeaders::Configuration.default do |config|
2018-01-13 08:38:33 -07:00
config.hsts = "max-age=#{1.week.to_i}"
config.x_frame_options = "DENY"
config.x_content_type_options = "nosniff"
config.x_xss_protection = "1; mode=block"
config.x_download_options = "noopen"
config.x_permitted_cross_domain_policies = "none"
2018-01-13 08:38:33 -07:00
config.referrer_policy = %w(
origin-when-cross-origin
strict-origin-when-cross-origin
)
config.csp = {
default_src: %w(https: 'self'),
base_uri: %w('self'),
block_all_mixed_content: false, # :( Some webcam feeds use http://
2018-01-13 08:38:33 -07:00
child_src: %w('self'),
2018-01-13 09:39:43 -07:00
connect_src: ALL_LOCAL_URIS + [ENV["MQTT_HOST"],
2018-01-13 08:20:28 -07:00
"api.github.com",
"raw.githubusercontent.com",
2018-01-13 08:29:15 -07:00
"openfarm.cc",
"api.rollbar.com"] +
2018-01-13 08:20:28 -07:00
(Rails.env.production? ? %w(wss:) : %w(ws: localhost:3000 localhost:3808)),
2018-01-13 08:38:33 -07:00
font_src: %w(
'self'
data:
maxcdn.bootstrapcdn.com
fonts.googleapis.com
fonts.gstatic.com
),
form_action: %w('self'),
frame_ancestors: %w(*), # We need "*" to support webcam users.
img_src: %w(* data:), # We need "*" to support webcam users.
manifest_src: %w('self'),
2018-01-13 08:20:28 -07:00
media_src: %w(),
object_src: %w(),
2018-01-13 08:38:33 -07:00
sandbox: %w(
allow-scripts
allow-forms
allow-same-origin
allow-modals
),
2018-01-13 08:20:28 -07:00
plugin_types: %w(),
2018-01-13 08:38:33 -07:00
script_src: %w(
'self'
'unsafe-eval'
'unsafe-inline'
cdnjs.cloudflare.com
chrome-extension:
localhost:3808
),
style_src: %w(
'unsafe-inline'
fonts.googleapis.com
maxcdn.bootstrapcdn.com
fonts.gstatic.com
),
2018-01-13 08:20:28 -07:00
worker_src: %w(),
2018-01-13 08:33:34 -07:00
upgrade_insecure_requests: false, # WHY? Some people run webcam feeds
# over plain http://. I wish they
# wouldn't, but I think it's too much
# of an inconvinience to block that
# feature. Comments welcome -RC.
2018-01-13 09:12:28 -07:00
report_uri: %w(/csp_reports)
}
end
2014-03-12 07:42:11 -06:00
end
end