-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaddyfile
More file actions
86 lines (77 loc) · 2.54 KB
/
Copy pathCaddyfile
File metadata and controls
86 lines (77 loc) · 2.54 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
:8080 {
root * /usr/share/caddy
encode gzip zstd
# route forces declaration order so @forbidden and asset handling run
# before document fallbacks.
route {
# Block access to sensitive paths
@forbidden {
path /.git/* /node_modules/* /vendor/* /.venv/*
}
respond @forbidden 404
# Requests with a non-HTML extension are assets. They must never
# fall back to index.html.
@asset {
path_regexp \.[A-Za-z0-9]+$
not path *.html *.htm
}
handle @asset {
file_server
}
# Serve real document files directly: the path as-is, then with a
# .html suffix, then as a directory index.
@documentFile file {path} {path}.html {path}/index.html
handle @documentFile {
rewrite * {http.matchers.file.relative}
file_server
}
# Document-like misses:
# - If /404.html exists in the site root, treat the site as an MPA
# and serve it with a real 404 status.
# - Otherwise, treat it as a SPA and serve /index.html normally.
# Avoid `file_server status 200` here; it also overrides 304/206
# generated by http.ServeContent for conditional and range requests.
@hasMpa404 file /404.html
handle @hasMpa404 {
rewrite * /404.html
# Strip range headers so http.ServeContent always serves the full
# file; the status 404 override then applies to a clean 200.
request_header -Range
request_header -If-Range
# Fresh requests get an explicit 404; revalidation requests
# (If-None-Match / If-Modified-Since) reach file_server unmodified
# so http.ServeContent can return 304 instead of an empty 404.
@mpa404Fresh {
not header If-None-Match *
not header If-Modified-Since *
}
route {
handle @mpa404Fresh {
file_server {
status 404
}
}
handle {
file_server
}
}
}
handle {
rewrite * /index.html
file_server
}
}
handle_errors 404 {
@asset {
path_regexp \.[A-Za-z0-9]+$
not path *.html *.htm
}
handle @asset {
respond "Not Found" 404
}
}
zeaburextension
log {
output stderr
}
}