vagrant/website/www/config.ru

55 lines
1.7 KiB
Plaintext
Raw Normal View History

2013-09-03 20:48:55 +00:00
require "rack"
require "rack/contrib/not_found"
require "rack/contrib/response_headers"
require "rack/contrib/static_cache"
require "rack/contrib/try_static"
2015-07-13 15:38:20 +00:00
require "rack/protection"
2013-09-03 20:48:55 +00:00
require File.expand_path("../lib/legacy_redirect", __FILE__)
2015-10-26 15:29:54 +00:00
require File.expand_path("../lib/redirect_to_releases", __FILE__)
2013-09-03 20:48:55 +00:00
2015-07-13 15:38:20 +00:00
# Protect against various bad things
use Rack::Protection::JsonCsrf
use Rack::Protection::RemoteReferrer
use Rack::Protection::HttpOrigin
use Rack::Protection::EscapedParams
use Rack::Protection::XSSHeader
use Rack::Protection::FrameOptions
use Rack::Protection::PathTraversal
use Rack::Protection::IPSpoofing
2013-09-03 20:48:55 +00:00
# Properly compress the output if the client can handle it.
use Rack::Deflater
# Redirect the legacy URLs that point to www.vagrantup.com
use HashiCorp::Rack::LegacyRedirect
2015-10-26 15:29:54 +00:00
# Redirect the archive page to releases
use HashiCorp::Rack::RedirectToReleases
2013-09-03 20:48:55 +00:00
# Set the "forever expire" cache headers for these static assets. Since
# we hash the contents of the assets to determine filenames, this is safe
# to do.
use Rack::StaticCache,
root: "build",
urls: ["/images", "/javascripts", "/stylesheets"],
duration: 2,
versioning: false
2013-09-03 20:48:55 +00:00
# For anything that matches below this point, we set the surrogate key
# for Fastly so that we can quickly purge all the pages without touching
# the static assets.
use Rack::ResponseHeaders do |headers|
headers["Surrogate-Key"] = "page"
end
# Try to find a static file that matches our request, since Middleman
# statically generates everything.
use Rack::TryStatic,
root: "build",
urls: ["/"],
try: [".html", "index.html", "/index.html"]
2013-09-03 20:48:55 +00:00
# 404 if we reached this point. Sad times.
run Rack::NotFound.new(File.expand_path("../build/404.html", __FILE__))