Farmbot-Web-App/config/application.rb

134 lines
5.1 KiB
Ruby
Raw Normal View History

require_relative "../app/models/transport.rb"
2019-04-17 14:48:54 -06:00
require File.expand_path("../boot", __FILE__)
require_relative "../app/lib/celery_script/cs_heap"
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)
2019-04-17 14:48:54 -06:00
module FarmBot
2014-03-12 07:42:11 -06:00
class Application < Rails::Application
2018-04-18 15:50:20 -06:00
Delayed::Worker.max_attempts = 4
2018-10-05 09:58:16 -06:00
REDIS_ENV_KEY = ENV.fetch("WHERE_IS_REDIS_URL", "REDIS_URL")
2019-04-17 14:48:54 -06:00
REDIS_URL = ENV.fetch(REDIS_ENV_KEY, "redis://redis:6379/0")
2019-07-25 12:10:06 -06:00
gcs_enabled =
%w[ GOOGLE_CLOUD_KEYFILE_JSON GCS_PROJECT GCS_BUCKET ].all? { |s| ENV.key? s }
config.load_defaults 6.0
2019-07-25 12:10:06 -06:00
config.active_storage.service = gcs_enabled ?
:google : :local
2019-04-17 14:48:54 -06:00
config.cache_store = :redis_cache_store, { url: REDIS_URL }
2019-04-18 12:46:00 -06:00
config.middleware.use Rack::Attack
2018-07-19 08:54:42 -06:00
config.active_record.schema_format = :sql
config.active_record.belongs_to_required_by_default = false
2019-04-17 14:48:54 -06: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
2019-01-30 07:00:26 -07:00
LOCAL_API_HOST = ENV.fetch("API_HOST", "parcel")
2019-04-17 14:48:54 -06:00
PARCELJS_URL = "http://#{LOCAL_API_HOST}:3808"
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
2019-04-17 14:48:54 -06:00
g.fixture_replacement :factory_bot, :dir => "spec/factories"
2014-05-08 08:02:51 -06:00
end
2019-04-17 14:48:54 -06:00
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
2019-04-17 14:48:54 -06:00
origins "*"
resource "/api/*",
2015-10-20 13:25:08 -06:00
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
API_PORT = ENV["API_PORT"]
2018-01-23 10:18:20 -07:00
Rails.application.routes.default_url_options[:host] = LOCAL_API_HOST
Rails.application.routes.default_url_options[:port] = API_PORT || 3000
2016-11-08 15:09:46 -07:00
# ¯\_(ツ)_/¯
2019-04-17 14:48:54 -06:00
$API_URL = "//#{Rails.application.routes.default_url_options[:host]}:#{Rails.application.routes.default_url_options[:port]}"
ALL_LOCAL_URIS = ([ENV["API_HOST"]] + (ENV["EXTRA_DOMAINS"] || "").split(","))
2018-01-13 09:39:43 -07:00
.map { |x| x.present? ? "#{x}:#{ENV["API_PORT"]}" : nil }.compact
SecureHeaders::Configuration.default do |config|
2019-04-17 14:48:54 -06:00
config.hsts = "max-age=#{1.week.to_i}"
2018-03-26 09:35:54 -06:00
# We need this off in dev mode otherwise email previews won't show up.
config.x_frame_options = "ALLOW-FROM https://farm.bot" # For marketing demos
2019-04-17 14:48:54 -06:00
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"
2019-06-19 11:45:46 -06:00
config.referrer_policy =
%w(origin-when-cross-origin strict-origin-when-cross-origin)
2019-02-01 08:38:27 -07:00
connect_src = ALL_LOCAL_URIS + [
ENV["MQTT_HOST"],
"api.github.com",
"raw.githubusercontent.com",
"openfarm.cc",
"api.rollbar.com",
PARCELJS_URL,
ENV["FORCE_SSL"] ? "wss:" : "ws:",
"localhost:#{API_PORT}",
2019-02-01 08:38:27 -07:00
"localhost:3808",
"browser-http-intake.logs.datadoghq.com",
"#{ENV.fetch("API_HOST")}:#{API_PORT}",
2019-02-01 08:38:27 -07:00
"#{ENV.fetch("API_HOST")}:3808",
]
config.csp = {
default_src: %w(https: 'self'),
base_uri: %w('self'),
block_all_mixed_content: false, # :( Some webcam feeds use http://
2019-02-01 08:38:27 -07:00
connect_src: connect_src,
2018-01-13 08:38:33 -07:00
font_src: %w(
'self'
data:
maxcdn.bootstrapcdn.com
fonts.googleapis.com
fonts.gstatic.com
),
2019-04-17 14:48:54 -06:00
form_action: %w('self'),
frame_src: %w(*), # We need "*" to support webcam users.
img_src: %w(* data:), # We need "*" to support webcam users.
manifest_src: %w('self'),
2019-04-17 14:48:54 -06: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
allow-popups
2018-01-13 08:38:33 -07:00
),
2018-01-13 08:20:28 -07:00
plugin_types: %w(),
script_src: [
"'self'",
"'unsafe-eval'",
"'unsafe-inline'",
"cdnjs.cloudflare.com",
"chrome-extension:",
"localhost:3808",
2019-02-01 07:56:03 -07:00
PARCELJS_URL,
"www.datadoghq-browser-agent.com",
],
2018-01-13 08:38:33 -07:00
style_src: %w(
2018-04-03 10:23:22 -06:00
'self'
2018-01-13 08:38:33 -07:00
'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
2019-02-19 19:10:08 -07:00
# of an inconvenience to block that
2018-01-13 08:33:34 -07:00
# feature. Comments welcome -RC.
2019-04-17 14:48:54 -06:00
report_uri: %w(/csp_reports),
}
end
2014-03-12 07:42:11 -06:00
end
end