summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/starlarkmw/tools/gen/example.star
blob: 6ccab32fb135a3cb94dea1860823bd411c0dd4a8 (plain)
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
# any module that provisions resources
proxyConfig = {
	'load_balance_type': 'round_robin',
	'upstreams': [
		{
			'host': 'http://localhost:8080',
			'circuit_breaker': {
				'type': 'status_ratio',
				'threshold': 0.5
			}
		},
		{
			'host': 'http://localhost:8081'
		}
	]
}

sfConfig = {
	'root': '/Users/dev/Desktop',
	'browse': {},
}

proxy = loadResponder('reverse_proxy', proxyConfig)
static_files = loadResponder('file_server', sfConfig)

def setup(r):
	# create some middlewares specific to this request
	mid = []

	if r.query.get('log') == 'true':
		logMid = loadMiddleware('log', {'file': 'access.log'})
		mid.append(logMid)

	execute(mid)

def serveHTTP(w, r):
	if r.url.find('static') > 0:
		return static_files

	return proxy