-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCaddyfile.j2
222 lines (201 loc) · 5.72 KB
/
Caddyfile.j2
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Snippet to allow working with git checkouts of project sites that become
# toplevel directories.
(subproject) {
# Caddy doesn't know this is a directory, so redirect to trailing / as
# would usually happen for them.
redir /{args[1]} /{args[1]}/ permanent
handle_path /{args[1]}/* {
root * {{ caddy.site_dir }}/{args[0]}
try_files {path}.html {path}
file_server {
hide .git
}
}
}
# Setup webhooks
{% if caddy.tls_config is defined %}
https://{{ caddy.addresses.webhook }} {
{{ caddy.tls_config }}
{% else %}
http://{{ caddy.addresses.webhook }} {
{% endif %}
# Include access logs when an error occurs, since we mask any internal errors
# from escaping to the outside world, but otherwise don't log.
log {
output discard
}
log errors {
no_hostname
}
root * {{ caddy.site_dir }}
request_body {
max_size 25MB # Limit from GitHub.
}
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#delivery-headers
@valid_webhook {
path /gh/*
method POST
header Content-Type application/json
header User-Agent GitHub-Hookshot/*
header X-GitHub-Event ping
header X-GitHub-Event push
header X-GitHub-Delivery *
header X-Hub-Signature-256 *
}
handle @valid_webhook {
reverse_proxy * localhost:1234 {
# Don't leak out internal problems.
@error status 4xx 5xx
handle_response @error {
log_name errors
log_append api_error_code {rp.status_code}
log_append api_error_text {rp.status_text}
error 400
}
}
}
handle /ping {
reverse_proxy * localhost:1234 {
# Don't leak out internal problems.
@error status 4xx 5xx
handle_response @error {
log_name errors
log_append api_error_code {rp.status_code}
log_append api_error_text {rp.status_text}
error 503
}
}
}
handle {
error 404
}
}
{% if caddy.tls_config is defined %}
https://{{ caddy.addresses.main }}, https://{{ ansible_fqdn }} {
{{ caddy.tls_config }}
{% else %}
http://{{ caddy.addresses.main }}, http://{{ ansible_fqdn }} {
{% endif %}
root * {{ caddy.site_dir }}
request_body {
max_size 0
}
{% for site, path in repos.items() %}
import subproject {{ site }} {{ path | default(site, true) }}
{% endfor %}
# Hide mpl-altair until the site is fixed.
redir /mpl-altair https://github.com/matplotlib/mpl-altair temporary
redir /mpl-altair/* https://github.com/matplotlib/mpl-altair temporary
# redirect the objects.inv
redir /objects.inv /stable/objects.inv permanent
# Make search go to the actual docs instead of the mostly-empty brochure site.
redir /search.html /stable/search.html?{query} temporary
# Redirect contributing guides to latest version.
# If you go to /devel/...?reallystable=1 you can avoid the redirect.
@devel {
path /stable/devel /stable/devel/*
not query reallystable=1
}
handle @devel {
route {
uri strip_prefix /stable
redir * /devdocs{uri}
}
}
# Redirect the repo-named third-party packages path to the more-generic path.
redir /3pp /thirdpartypackages/ # And also add a shortcut.
@mpl-third-party path /mpl-third-party /mpl-third-party/*
handle @mpl-third-party {
route {
uri strip_prefix /mpl-third-party
redir * /thirdpartypackages{uri}
}
}
# Place the brochure site at the top level.
@brochure file {
root {{ caddy.site_dir }}/mpl-brochure-site
try_files {path}.html {path}
}
rewrite / /mpl-brochure-site/index.html
rewrite @brochure /mpl-brochure-site{http.matchers.file.relative}
# Redirect any of the old top-level files to the versioned docs.
redir /citing.html /stable/project/citing.html permanent
redir /contents.html /stable/users/ permanent
redir /downloads.html /stable/users/installing/ permanent
redir /gallery.html /stable/gallery/ permanent
redir /py-modindex.html /stable/py-modindex.html permanent
{# 3.5.0 was the last version to be synced to the top-level directory.
We also try for stable, just to go to the best version possible. #}
{%- with old_versions = [
"stable",
"3.5.0",
"3.4.3", "3.4.2", "3.4.1", "3.4.0",
"3.3.4", "3.3.3", "3.3.2", "3.3.1", "3.3.0",
"3.2.2", "3.2.1", "3.2.0",
"3.1.3", "3.1.1", "3.1.0",
"3.0.3", "3.0.2", "3.0.0",
"2.2.5", "2.2.4", "2.2.3", "2.2.2", "2.2.0",
"2.1.2", "2.1.1", "2.1.0",
"2.0.2", "2.0.1", "2.0.0",
"1.5.3", "1.5.1", "1.5.0",
"1.4.3", "1.4.2", "1.4.1", "1.4.0",
"1.3.1", "1.3.0", "1.2.1",
] %}
{%- with old_toplevel_dirs = [
"_downloads",
"_images",
"_modules",
"_panels_static",
"_sources",
"_static",
"api",
"devel",
"examples",
"faq",
"gallery",
"glossary",
"mpl_examples",
"mpl_toolkits",
"plot_directive",
"plot_types",
"pyplots",
"resources",
"tutorials",
"users",
] %}
@old-toplevel-dirs {
path{% for dir in old_toplevel_dirs %} /{{dir}} /{{dir}}/{% endfor +%}
file {
root {{ caddy.site_dir }}/matplotlib.github.com
try_files{% for version in old_versions %} /{{version}}/{path}/index.html{% endfor +%}
}
}
redir @old-toplevel-dirs {http.matchers.file.relative} permanent
@old-toplevel-dir-contents {
path{% for dir in old_toplevel_dirs %} /{{dir}}/*{% endfor +%}
file {
root {{ caddy.site_dir }}/matplotlib.github.com
try_files{% for version in old_versions %} /{{version}}/{path}.html /{{version}}/{path}{% endfor +%}
}
}
redir @old-toplevel-dir-contents {http.matchers.file.relative} permanent
{%- endwith -%}
{%- endwith +%}
# Finally try any of the versioned docs.
handle {
root * {{ caddy.site_dir }}/matplotlib.github.com
try_files {path}.html {path}
file_server {
hide .git
}
}
# Use a custom 404 error page.
handle_errors {
@notfound expression {http.error.status_code} == 404
root * {{ caddy.site_dir }}/mpl-brochure-site
rewrite @notfound /404.html
file_server {
hide .git
}
}
}