-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.vcl
89 lines (75 loc) · 1.77 KB
/
test.vcl
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
vcl 4.0;
import accept;
import directors;
import jwt;
import std;
import var;
probe localhost_probe {
.url = "/_health";
.interval = 5s;
.timeout = 3.14s;
.threshold = 3;
}
backend localhost {
.host = "localhost";
.port = "8080";
.probe = localhost_probe;
}
backend localhost_8081 {
.host = "localhost";
.port = "8081";
.probe = localhost_probe;
}
sub vcl_init {
var.global_set("hello", "world");
new vdir = directors.round_robin();
new jwt_reader = jwt.reader();
if (var.global_get("hello") == "darkness") {
std.syslog(3, "my old friend");
return(fail);
}
}
sub add_cors_header {
if (req.http.origin ~ "https?://darthvader.no") {
set req.http.access-control-allow-origin = req.http.origin;
}
}
acl acl_purge {
"localhost";
"10.0.0.0/8"; // hello
"192.168.0.0"/16; // world
}
sub vcl_recv {
if (req.restarts == 0) {
// httpoxy
unset req.http.proxy;
}
if (req.method == "PURGE") {
if (client.ip !~ acl_purge || !jwt_reader.parse(req.http.Authorization)) {
return(synth(405, "Could not purge"));
}
return(hash);
}
if (req.url == "/_health") {
return(synth(200, "ok"));
} elsif (req.url ~ "^/api") {
set req.backend_hint = localhost;
call add_cors_header;
return(pass);
} elsif (req.url ~ "^/martin") {
synthetic({"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Martin var her</title>
</head>
<body>
Martin er best, ingen protest.
</body>
</html>
"});
} else {
set req.http.x-test = "test";
}
}