-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.ru
23 lines (19 loc) · 829 Bytes
/
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
require 'rack'
require 'rack/contrib/try_static'
env = ENV['RACK_ENV'] || 'development'
dir = if env == 'development' then 'build/site' else '__released_site' end
# enable compression
use Rack::Deflater
# static configuration (file path matches reuest path)
use Rack::TryStatic,
:root => dir, # static files root dir
:urls => %w[/], # match all requests
:try => ['.html', 'index.html', '/index.html'], # try these postfixes sequentially
:gzip => true, # enable compressed files
:header_rules => [
[:all, {'Cache-Control' => 'public, max-age=86400'}],
[['css', 'js'], {'Cache-Control' => 'public, max-age=604800'}]
]
# otherwise 404 NotFound
notFoundPage = File.open("#{dir}/index.html").read
run lambda { |_| [200, {'Content-Type' => 'text/html'}, [notFoundPage]]}