-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ru
49 lines (45 loc) · 1.12 KB
/
config.ru
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
use Rack::Static,
:urls => ["/img", "/js", "/css", "/fonts", "/includes"],
:root => "public"
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
end
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
map '/mail' do
run lambda { |env|
request = Rack::Request.new(env)
case request.request_method
when 'POST'
begin
Mail.deliver do
to '[email protected]'
from "#{request.params['name']}<#{request.params['email']}>"
subject 'Contato pelo Site CREA Mais Profissional'
body request.params['message']
end
rescue
[200, {'Content-Type' => 'text/plain'}, ['error']]
else
[200, {'Content-Type' => 'text/plain'}, ['success']]
end
end
}
end