-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCaddyfile.j2
More file actions
138 lines (122 loc) · 3.73 KB
/
Caddyfile.j2
File metadata and controls
138 lines (122 loc) · 3.73 KB
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
# 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.0} /{args.0}/ permanent
handle_path /{args.0}/* {
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 %}
root * {{ caddy.site_dir }}
# 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 {
error 400
}
}
}
handle /ping {
reverse_proxy * localhost:1234 {
# Don't leak out internal problems.
@error status 4xx 5xx
handle_response @error {
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 }}
{% for site in repos %}
import subproject {{ site }}
{% endfor %}
# Moved matplotblog to Scientific Python blog.
##############################################
# Top-level post listings go to matplotlib tag.
@matplotblog {
path /matplotblog
path /matplotblog/
path /matplotblog/index.html
path /matplotblog/posts
path /matplotblog/posts/
path /matplotblog/posts/index.html
path /matplotblog/page
path /matplotblog/page/*
}
redir @matplotblog https://blog.scientific-python.org/tags/matplotlib/
# New blog doesn't do any post-processing of images, so go to original image.
@matplotblog_processed_image {
path_regexp image /matplotblog/posts/(.*)_hu[a-z0-9]+_[0-9]+_(400x300_fit|800x0_resize)_(q75_lanczos|lanczos_3).(png|jpeg|jpg)
}
redir @matplotblog_processed_image https://blog.scientific-python.org/posts/matplotlib/{re.image.1}.{re.image.4}
# Special cases.
redir /matplotblog/posts/how-to-contribute https://blog.scientific-python.org/submitting/
redir /matplotblog/posts/how-to-contribute/* https://blog.scientific-python.org/submitting/
# Everything else is a post or its assets, so redirect to the right post page/asset.
@matplotblog_post {
path_regexp post /matplotblog/posts/(.*)
}
redir @matplotblog_post https://blog.scientific-python.org/posts/matplotlib/{re.post.1}
# 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
# 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}
# 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
}
}
}