-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroutes.rb
59 lines (53 loc) · 1.65 KB
/
routes.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
require 'sinatra'
require 'newrelic_rpm'
require 'json'
require 'sinatra'
require 'dalli'
require 'rack-cache'
require 'memcachier'
hash = {
name: "John Figueiredo",
email: "john@johnfigueiredo.com",
phone: "415.852.8871",
github: "http://github.com/johnfig",
portfolio: "www.johnfigueiredo.com",
twitter: "@FigueiredoJohn",
linkedin: "http://www.linkedin.com/pub/john-figueiredo/11/17/a45"
}
set :email_username, ENV['SENDGRID_USERNAME'] || 'john@johnfigueiredo.com'
set :email_password, ENV['SENDGRID_PASSWORD'] || 'jfig3333'
set :email_address, 'john@johnfigueiredo.com'
set :email_service, ENV['EMAIL_SERVICE'] || 'gmail.com'
set :email_domain, ENV['SENDGRID_DOMAIN'] || 'localhost.localdomain'
get '/' do
cache_control :public, max_age: 86400 # 24 hours
File.read(File.join('public', 'index.html'))
end
get '/info' do
content_type :json
hash.to_json
end
post '/contact' do
if params[:email]
require 'pony'
Pony.mail(
:from => params[:name] + "<" + params[:email] + ">",
:to => settings.email_address,
:subject => params[:name] + " has contacted you",
:body => params[:message],
:port => '587',
:via => :smtp,
:via_options => {
:address => 'smtp.' + settings.email_service,
:port => '587',
:enable_starttls_auto => true,
:user_name => settings.email_username,
:password => settings.email_password,
:authentication => :plain,
:domain => settings.email_domain
})
redirect '/'
else
redirect '/'
end
end