sharieswebsite/config.ru

62 lines
2 KiB
Text
Raw Normal View History

2011-04-04 14:09:11 +00:00
require 'rubygems'
require 'rack'
require 'rack/contrib'
2011-05-13 20:11:54 +00:00
require 'rack-rewrite'
2011-04-04 14:09:11 +00:00
require 'rack/trystatic'
require 'mime/types'
2011-05-12 20:20:57 +00:00
require 'pony'
2011-04-04 14:09:11 +00:00
use Rack::Deflater
use Rack::ETag
2011-05-13 20:11:54 +00:00
use Rack::Rewrite do
r302 %r{/support}, 'http://ypassword.espozito.com/Scratch/en/support'
end
2011-04-04 14:09:11 +00:00
$rootdir="site"
2011-05-12 20:20:57 +00:00
$errorFile='site/404.html'
$mailFile='site/mail_sent.html'
class MyMain < Rack::TryStatic
def call(env)
request = Rack::Request.new(env)
if request.path == "/contact" and request.post?
2011-05-12 20:55:37 +00:00
Pony.mail(
:from => request[:name] + '<' + request[:mail] +'>',
:to => "yann.esposito@gmail.com",
:subject => 'YPassword support',
:body => request[:body],
:port => '587',
:via => :smtp,
:via_options => {
:address => 'smtp.sendgrid.net',
:port => '587',
:enable_starttls_auto => true,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentification => :plain,
:domain => ENV['SENDGRID_DOMAIN'],
})
2011-05-12 20:20:57 +00:00
return [200, {
"Last-Modified" => File.mtime($mailFile).httpdate,
"Content-Type" => "text/html",
"Content-Length" => File.size($mailFile).to_s
}, File.read($mailFile)]
else
super
end
end
end
use MyMain,
2011-04-04 14:09:11 +00:00
:root => $rootdir, # static files root dir
:urls => %w[/], # match all requests
:try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially
run lambda { [404, {
2011-05-12 20:20:57 +00:00
"Last-Modified" => File.mtime($errorFile).httpdate,
2011-04-04 14:09:11 +00:00
"Content-Type" => "text/html",
2011-05-12 20:20:57 +00:00
"Content-Length" => File.size($errorFile).to_s
}, File.read($errorFile)] }