forked from Scalingo/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ru
66 lines (53 loc) · 2.05 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'rack/jekyll'
require 'rack/rewrite'
require 'rack/ssl-enforcer'
require 'rack/canonical_host'
require 'yaml'
class Object
def blank?
respond_to?(:empty?) ? empty? : !self
end
def present?
!blank?
end
end
use Rack::Rewrite do
r301 %r{.*}, "https://#{ ENV['CANONICAL_HOST'] }/samples$&", if: Proc.new {|rack_env|
['samples.scalingo.com'].include?(rack_env['SERVER_NAME'])
}
r301 "/samples/", "/samples"
r301 %r{.*}, "https://#{ ENV['CANONICAL_HOST'] }/changelog$&", if: Proc.new {|rack_env|
['changelog.scalingo.com'].include?(rack_env['SERVER_NAME'])
}
r301 "/changelog/", "/changelog"
r301 %r{.*}, "https://#{ ENV['CANONICAL_HOST'] }/cli$&", if: Proc.new {|rack_env|
['cli.scalingo.com'].include?(rack_env['SERVER_NAME'])
}
r301 "/cli/", "/cli"
r301 /\/internals\/(.*)-buildpack/, "/platform/deployment/buildpacks/$1"
r301 /\/addons\/scalingo-postgresql(.*)/, "/databases/postgresql$1"
r301 /\/addons\/scalingo-mysql(.*)/, "/databases/mysql$1"
r301 /\/addons\/scalingo-mongodb(.*)/, "/databases/mongodb$1"
r301 /\/addons\/scalingo-elasticsearch(.*)/, "/databases/elasticsearch$1"
r301 /\/addons\/scalingo-influxdb(.*)/, "/databases/influxdb$1"
redirections = YAML.load_file('redirections.yml')
redirections['301'].each{|redir|
r301 redir["old"], redir["new"]
}
redirections['obsolete'].each{|redir|
r301 redir, "/"
}
r301 %r{^(.+).html$}, '$1'
rewrite %r{^([^?]+)(\??)(.*)}, '$1.html$2$3', if: Proc.new {|rack_env|
rack_env['PATH_INFO'].present? && rack_env['PATH_INFO'] != '/' && rack_env['PATH_INFO'] !~ /\.(jpg|jpeg|png|gif|ico|eot|otf|ttf|woff|woff2|css|js|xml|txt)$/i
}
end
if ENV['FORCE_SSL'].present?
use Rack::SslEnforcer
end
if ENV['CANONICAL_HOST'].present? && ENV['CANONICAL_HOST_DISABLED'].blank?
canonical_hosts_ignore = ENV['CANONICAL_HOSTS_IGNORE'].present? ? ENV['CANONICAL_HOSTS_IGNORE'].split(",").map(&:strip) : []
use Rack::CanonicalHost, ENV['CANONICAL_HOST'], ignore: canonical_hosts_ignore
end
use Rack::CommonLogger
run Rack::Jekyll.new