Merge branch 'wtsi/13809-root_url-protocol-port-configuration'
[arvados.git] / services / api / config / application.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require File.expand_path('../boot', __FILE__)
6
7 require 'rails/all'
8 require 'digest'
9
10 module Kernel
11   def suppress_warnings
12     verbose_orig = $VERBOSE
13     begin
14       $VERBOSE = nil
15       yield
16     ensure
17       $VERBOSE = verbose_orig
18     end
19   end
20 end
21
22 if defined?(Bundler)
23   suppress_warnings do
24     # If you precompile assets before deploying to production, use this line
25     Bundler.require(*Rails.groups(:assets => %w(development test)))
26     # If you want your assets lazily compiled in production, use this line
27     # Bundler.require(:default, :assets, Rails.env)
28   end
29 end
30
31 module Server
32   class Application < Rails::Application
33     # The following is to avoid SafeYAML's warning message
34     SafeYAML::OPTIONS[:default_mode] = :safe
35
36     # Settings in config/environments/* take precedence over those specified here.
37     # Application configuration should go into files in config/initializers
38     # -- all .rb files in that directory are automatically loaded.
39
40     # Custom directories with classes and modules you want to be autoloadable.
41     # config.autoload_paths += %W(#{config.root}/extras)
42
43     # Only load the plugins named here, in the order given (default is alphabetical).
44     # :all can be used as a placeholder for all plugins not explicitly named.
45     # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
46
47     # Activate observers that should always be running.
48     # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
49     config.active_record.schema_format = :sql
50
51     # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
52     # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
53     # config.i18n.default_locale = :de
54
55     # Configure sensitive parameters which will be filtered from the log file.
56     config.filter_parameters += [:password]
57
58     # Load entire application at startup.
59     config.eager_load = true
60
61     config.active_record.raise_in_transactional_callbacks = true
62
63     config.active_support.test_order = :sorted
64
65     config.action_dispatch.perform_deep_munge = false
66
67     I18n.enforce_available_locales = false
68
69     # Before using the filesystem backend for Rails.cache, check
70     # whether we own the relevant directory. If we don't, using it is
71     # likely to either fail or (if we're root) pollute it and cause
72     # other processes to fail later.
73     default_cache_path = Rails.root.join('tmp', 'cache')
74     if not File.owned?(default_cache_path)
75       if File.exist?(default_cache_path)
76         why = "owner (uid=#{File::Stat.new(default_cache_path).uid}) " +
77           "is not me (uid=#{Process.euid})"
78       else
79         why = "does not exist"
80       end
81       STDERR.puts("Defaulting to memory cache, " +
82                   "because #{default_cache_path} #{why}")
83       config.cache_store = :memory_store
84     else
85       require Rails.root.join('lib/safer_file_store')
86       config.cache_store = ::SaferFileStore.new(default_cache_path)
87     end
88   end
89 end