-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.rb
More file actions
57 lines (56 loc) · 1.75 KB
/
Copy pathapp.rb
File metadata and controls
57 lines (56 loc) · 1.75 KB
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
require 'sinatra/base'
require 'sinatra/json'
require 'sinatra/config_file'
require 'slack-notifier'
require 'pony'
require 'dotenv'
require 'redcarpet'
Dotenv.load
require_relative 'server/helpers/logger'
require_relative 'db/init'
# common controller for other controllers to inherit from.
# routes should not be defined here since this controller
# is effectively "mounted" at serveral places in the rack
# app (meaning routes defined here would be unintentially
# available in other random places).
# only common config and setup should be defined here
class ApplicationController < Sinatra::Base
VERSION = '0.3.0'.freeze
extend MagicLogger
register Sinatra::ConfigFile
config_file 'config.yml'
configure do
enable :sessions
enable :logging
set :views, ['server/views']
set :logger, logger
set :method_override, false
end
::MarkdownService = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
Pony.options = {
from: 'noreply@magic-stick.herokuapp.com',
via: (ENV['RACK_ENV'] == 'production' ? :smtp : :test),
via_options: {
address: 'smtp.sendgrid.net',
port: '587',
domain: 'heroku.com',
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true
}
}
before do
content_type 'application/json'
end
end
# load all server helpers and files
root_dir = File.dirname(__FILE__)
%w(helpers models controllers).each do |type|
Dir["#{root_dir}/server/#{type}/*.rb"].each do |file|
require file
end
end
# for some reason this was the only place I could register the helper
# with the controller; i'm sure there is a better way TODO
ApplicationController.helpers Slack, Request, Auth, Link, Email