diaspora/config/initializers/_load_app_config.rb
Alec Leamas eacee54846 Replace APP_CONFIG[:terse_pod_url] with uri object.
Adds a new APP_CONFIG[:pod_uri] item, an uri object parsed from
pod_url. Replace all occurrences of APP_CONFIG[:terse_pod_url] with
APP_CONFIG[:pod_uri].host. Closes http://bugs.joindiaspora.com/issues/684,
using the well-defined semantics of the uri object.

The pod_url is normalized using module URI's functions, always with a
trailing /.

The diaspora-handle will always reflect the pod_url with this patch
i. e., a pod_url like www.dpod.se will give the handle xx@www.dpod.se;
previous code stripped the www. prefix. If this is a problem, it
should be addressed by another setting, since one cannot presume that
www.domain.tld resolves to the same address as domain.tld.
2010-12-10 14:29:19 +01:00

42 lines
1.4 KiB
Ruby

# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
# Sets up APP_CONFIG. Unless stated below, each entry is a the string in
# the file app_config.yml, as applicable for current environment.
#
# Specific items
# * pod_url: As in app_config.yml, normalized with a trailing /.
# * pod_uri: An uri object derived from pod_url.
require 'uri'
def load_config_yaml filename
YAML.load(File.read(filename))
end
if File.exist? "#{Rails.root}/config/app_config.yml"
all_envs = load_config_yaml "#{Rails.root}/config/app_config.yml"
all_envs = load_config_yaml "#{Rails.root}/config/app_config.yml.example" unless all_envs
else
puts "WARNING: No config/app_config.yml found! Look at config/app_config.yml.example for help."
all_envs = load_config_yaml "#{Rails.root}/config/app_config.yml.example"
end
if all_envs[Rails.env.to_s]
APP_CONFIG = all_envs['default'].merge(all_envs[Rails.env.to_s]).symbolize_keys
else
APP_CONFIG = all_envs['default'].symbolize_keys
end
begin
APP_CONFIG[:pod_uri] = URI.parse( APP_CONFIG[:pod_url])
rescue
puts "WARNING: pod url " + APP_CONFIG[:pod_url] + " is not a legal URI"
end
APP_CONFIG[:pod_url] = APP_CONFIG[:pod_uri].normalize.to_s
if APP_CONFIG[:pod_uri].host == "example.org" && Rails.env != "test"
puts "WARNING: Please modify your app_config.yml to have a proper pod_url!"
end