-
Notifications
You must be signed in to change notification settings - Fork 39
/
environment.rb
76 lines (60 loc) · 2.46 KB
/
environment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Encoding.default_internal = 'UTF-8'
Encoding.default_external = 'UTF-8'
ENV['TZ'] = 'UTC'
require 'rubygems'
require 'bundler/setup'
require 'cgi'
require 'xmlrpc/marshal'
require 'securerandom'
require 'openssl'
Bundler.require :default, ENV['RACK_ENV']
Dir.glob(['lib', 'models', 'helpers'].map! {|d| File.join File.expand_path(File.dirname(__FILE__)), d, '*.rb'}).each {|f| require f}
unless File.exists? './config.yml'
puts 'Please provide a config.yml file.'
exit false
end
class ConfigHelper < Hashie::Mash
def key; self['key'] end
end
SiteConfig = ConfigHelper.new YAML.load_file('config.yml')[ENV['RACK_ENV']] if File.exists?('config.yml')
class Controller < Sinatra::Base
configure do
helpers Sinatra::UserAgentHelpers
# Set controller names so we can map them in the config.ru file.
set :controller_names, []
Dir.glob('controllers/*.rb').each do |file|
settings.controller_names << File.basename(file, '.rb')
# require_relative "./#{file}"
end
use Rack::Session::Cookie, :key => 'rack.session',
:path => '/',
:expire_after => 2592000,
:secret => SiteConfig.session_secret
set :root, File.dirname(__FILE__)
set :raise_errors, false
set :protection, :except => [:frame_options, :json_csrf]
if ENV['RACK_ENV'] == 'development'
set :show_exceptions, true
DataMapper::Logger.new(STDOUT, :debug)
else
set :show_exceptions, false
end
DataMapper.finalize
DataMapper.setup :default, SiteConfig.database_url
DataMapper.repository.adapter.execute('SET NAMES utf8mb4')
DataMapper.repository.adapter.execute('SET SESSION sql_mode = ""')
# This was added here and was supposed to be a fix for handling emoji in URLs:
# https://github.com/aaronpk/webmention.io/commit/1df6373363071c2d93e85d4d20b47fbe41424ed6
# However it instead seemed to break storing emoji in the post content entirely.
# Reverted this on 2023-11-06 and will come back to this later if emoji in URLs are still broken.
# https://github.com/aaronpk/webmention.io/issues/203
# DataMapper.repository.adapter.execute('SET collation_connection = "utf8mb4_general_ci";')
set :views, 'views'
set :erubis, :escape_html => true
set :public_folder, File.dirname(__FILE__) + '/public'
end
def p; params end
end
Dir.glob(['controllers'].map! {|d| File.join d, '*.rb'}).each do |f|
require_relative f
end