-
Notifications
You must be signed in to change notification settings - Fork 0
/
Caddyfile
130 lines (111 loc) · 5.96 KB
/
Caddyfile
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
{
order cache before rewrite
cache ttl 24h
}
(try) {
reverse_proxy @parts {args[0]} {
# Remove all headers to upstream - particularly the original host
header_up -*
# Remove all return headers from upstream - particulraly content-type
header_down -*
header_up Host {upstream_hostport}
rewrite {args[1]}
# Return content if found
@ok status 200
handle_response @ok {
copy_response
}
# Ignore not found
@error status 4xx
handle_response @error
# Follow redirect
@redirect status 3xx
handle_response @redirect {
rewrite {rp.header.Location}
reverse_proxy {args[0]} {
header_up -*
header_down -*
}
}
}
}
:80 {
log stdout
# Gitea host:port with public repositories with raw files
vars upstream "{$GITEA_HOST:git:3000}"
# Gitea raw urls return everything as text/plain
# Set content-type based on the extension
@extension path_regexp extension (.*)\.(\w+)
# got the list from somewhere on the internet - should reference here if I can find it back
map @extension {re.extension.2} {content_type} {
~^(?:appcache|manifest)$ text/cache-manifest;charset=utf-8
~^atom$ application/atom+xml;charset=utf-8
~^bat$ application/x-msdownload;
~^coffee$ text/coffeescript;charset=utf-8
~^css$ text/css;charset=utf-8
~^csv$ text/csv;charset=utf-8
~^eot$ application/vnd.ms-fontobject;
~^geojson$ application/vnd.geo+json;charset=utf-8
~^(?:hbs|handlebars)$ text/x-handlebars-template;
~^htc$ text/x-component;
~^html?$ text/html;charset=utf-8
~^ics$ text/calendar;charset=utf-8
~^jscad$ application/javascript;charset=utf-8
~^json$ application/json;charset=utf-8
~^jsonld$ application/ld+json;charset=utf-8
~^kml$ application/vnd.google-earth.kml+xml;charset=utf-8
~^(?:md|markdown)$ text/markdown;charset=utf-8
~^m?js$ application/javascript;charset=utf-8
~^mhtml$ multipart/related;charset=utf-8
~^n3$ text/n3;charset=utf-8
~^nt$ application/n-triples;
~^otf$ font/otf;
~^(?:owl|rdf)$ application/rdf+xml;charset=utf-8
~^pdf$ application/pdf;
~^rss$ application/rss+xml;charset=utf-8
~^shexc?$ text/shex;
~^svg$ image/svg+xml;
~^swf$ application/x-shockwave-flash;
~^stl$ model/stl;
~^tt(?:c|f)$ application/x-font-ttf;
~^ttl$ text/turtle;
~^vcard$ text/vcard;charset=utf-8
~^vcf$ text/x-vcard;charset=utf-8
~^vtt$ text/vtt;
~^woff$ application/font-woff;
~^woff2$ application/font-woff2;
~^xht(?:ml)?$ application/xhtml+xml;charset=utf-8
~^xml$ text/xml;charset=utf-8
~^txt$ text/plain;charset=utf-8
~^(?:xsl|xsd)$ application/xml;charset=utf-8
~^xslt$ application/xslt+xml;charset=utf-8
~^ya?ml$ text/yaml;charset=utf-8
~^wasm$ application/wasm;
~^(?:d|s)?rpm$ application/x-redhat-package-manager;
default text/html;charset=utf-8
}
header @extension Content-Type {content_type}
# get subdomain of the requested url
@parts header_regexp host Host ^(\w+)\..*$
# Look for the first file that we can find
# Example http://org.example.com/app/
# try http://gitea:3000/org/org.example.com/raw/branch/pages/app
import try {vars.upstream} /{re.host.1}/{host}/raw/branch/pages{path}
# try http://gitea:3000/org/org.example.com/raw/branch/pages/app/index.html
import try {vars.upstream} /{re.host.1}/{host}/raw/branch/pages{path}/index.html
# try http://gitea:3000/org/org.example.com/raw/branch/[defult branch: e.g. master or main]/app
import try {vars.upstream} /{re.host.1}/{host}/raw{path}
import try {vars.upstream} /{re.host.1}/{host}/raw{path}/index.html
#import try {vars.upstream} /{re.host.1}/{re.host.1}/raw/branch/pages{path}
#import try {vars.upstream} /{re.host.1}/{re.host.1}/raw/branch/pages{path}/index.html
#import try {vars.upstream} /{re.host.1}/{re.host.1}/raw{path}
#import try {vars.upstream} /{re.host.1}/{re.host.1}/raw{path}/index.html
# Default back to the full url - not using subdomain or host
# This is useful as it doesn't need subdomain or branch or
# any other defaults but it fixes the content type
@raw path_regexp raw ^\/[^\/]+\/[^\/]+\/raw\/\.*
reverse_proxy @raw {vars.upstream} {
header_up -*
header_down -*
}
}