blob: 97756f4c4f8baa78001f3b32a9bc229254a5b50d [file] [log] [blame]
Skyler Greyd7e1acd2024-06-22 14:42:11 +00001# SPDX-FileCopyrightText: 2024 Clicks Codes
2#
3# SPDX-License-Identifier: GPL-3.0-only
4
5{ lib, ... }: let
6 step0 = {
7 "calibre.clicks.codes" = {
8 service = lib.clicks.nginx.http.unsafeAddCrossOriginHeader (lib.clicks.nginx.http.reverseProxy "generic" 1024);
9 www = true;
10 dnsProvider = "cloudflare";
11 routes = null;
12 authWith = "tailscale";
13 enableHttp = false;
14 };
15 };
16 step1 = {
17 "calibre.clicks.codes" = {
18 service = {
19 _type = "header";
20 name = "Access-Control-Allow-Origin";
21 value = "*";
22 content = {
23 host = "generic";
24 port = 1024;
25 protocol = "http";
26 _type = "reverseProxy";
27 headers = null;
28 };
29 };
30 dnsProvider = "cloudflare";
31 routes = null;
32 authWith = "tailscale";
33 enableHttp = false;
34 };
35 "www.calibre.clicks.codes" = {
36 routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere {
37 to = "https://calibre.clicks.codes/$1";
38 permanent = true;
39 _type = "redirect";
40 headers = null;
41 };
42 authWith = null;
43 service = null;
44 enableHttp = false;
45 };
46 };
47 step2 = {
48 "calibre.clicks.codes" = {
49 routes."/" = lib.home-manager.hm.dag.entryAnywhere {
50 _type = "header";
51 name = "Access-Control-Allow-Origin";
52 value = "*";
53 content = {
54 host = "generic";
55 port = 1024;
56 protocol = "http";
57 _type = "reverseProxy";
58 headers = null;
59 };
60 };
61 dnsProvider = "cloudflare";
62 authWith = "tailscale";
63 enableHttp = false;
64 };
65 "www.calibre.clicks.codes" = {
66 routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere {
67 to = "https://calibre.clicks.codes/$1";
68 permanent = true;
69 _type = "redirect";
70 headers = null;
71 };
72 authWith = null;
73 enableHttp = false;
74 };
75 };
76 step3 = {
77 "calibre.clicks.codes" = {
78 routes = [
79 {
80 name = "/";
81 value = {
82 _type = "header";
83 name = "Access-Control-Allow-Origin";
84 value = "*";
85 content = {
86 host = "generic";
87 port = 1024;
88 protocol = "http";
89 _type = "reverseProxy";
90 headers = null;
91 };
92 };
93 }
94 ];
95 dnsProvider = "cloudflare";
96 authWith = "tailscale";
97 enableHttp = false;
98 };
99 "www.calibre.clicks.codes" = {
100 routes = [
101 {
102 name = "~ ^/?([^\r\n]*)$";
103 value = {
104 to = "https://calibre.clicks.codes/$1";
105 permanent = true;
106 _type = "redirect";
107 headers = null;
108 };
109 }
110 ];
111 authWith = null;
112 enableHttp = false;
113 };
114 };
115 step4 = {
116 "calibre.clicks.codes" = {
117 routes = [
118 {
119 name = "/";
120 value = {
121 host = "generic";
122 port = 1024;
123 protocol = "http";
124 _type = "reverseProxy";
125 headers = {
126 "Access-Control-Allow-Origin" = "*";
127 };
128 };
129 }
130 ];
131 dnsProvider = "cloudflare";
132 authWith = "tailscale";
133 enableHttp = false;
134 };
135 "www.calibre.clicks.codes" = {
136 routes = [
137 {
138 name = "~ ^/?([^\r\n]*)$";
139 value = {
140 to = "https://calibre.clicks.codes/$1";
141 permanent = true;
142 _type = "redirect";
143 headers = null;
144 };
145 }
146 ];
147 authWith = null;
148 enableHttp = false;
149 };
150 };
151 step5 = {
152 "calibre.clicks.codes" = {
153 locations = [
154 {
155 name = "/";
156 value = {
157 proxyPass = "http://generic:1024";
158 proxyWebsockets = true;
159 recommendedProxySettings = true;
160 extraConfig = "\nadd_header \"Access-Control-Allow-Origin\" \"*\";";
161 };
162 }
163 ];
164 dnsProvider = "cloudflare";
165 authWith = "tailscale";
166 enableHttp = false;
167 };
168 "www.calibre.clicks.codes" = {
169 locations = [
170 {
171 name = "~ ^/?([^\r\n]*)$";
172 value = {
173 return = "307 https://calibre.clicks.codes/$1";
174 };
175 }
176 ];
177 authWith = null;
178 enableHttp = false;
179 };
180 };
181 step6 = {
182 "calibre.clicks.codes" = {
183 locations."/" = {
184 priority = 100;
185 proxyPass = "http://generic:1024";
186 proxyWebsockets = true;
187 recommendedProxySettings = true;
188 extraConfig = "\nadd_header \"Access-Control-Allow-Origin\" \"*\";";
189 };
190 dnsProvider = "cloudflare";
191 authWith = "tailscale";
192 enableHttp = false;
193 };
194 "www.calibre.clicks.codes" = {
195 locations."~ ^/?([^\r\n]*)$" = {
196 return = "307 https://calibre.clicks.codes/$1";
197 priority = 100;
198 };
199 authWith = null;
200 enableHttp = false;
201 };
202 };
203 step7 = {
204 "calibre.clicks.codes" = {
205 locations."/" = {
206 priority = 100;
207 proxyPass = "http://generic:1024";
208 proxyWebsockets = true;
209 recommendedProxySettings = true;
210 extraConfig = "\nadd_header \"Access-Control-Allow-Origin\" \"*\";";
211 };
212 onlySSL = true;
213 addSSL = false;
214 useACMEHost = "calibre.clicks.codes";
215 dnsProvider = "cloudflare";
216 authWith = "tailscale";
217 };
218 "www.calibre.clicks.codes" = {
219 locations."~ ^/?([^\r\n]*)$" = {
220 return = "307 https://calibre.clicks.codes/$1";
221 priority = 100;
222 };
223 onlySSL = true;
224 addSSL = false;
225 useACMEHost = "www.calibre.clicks.codes";
226 authWith = null;
227 };
228 };
229in {
230 testGenerateWwwRedirects = {
231 expr = lib.clicks.nginx.http.internal.generateWwwRedirects step0;
232 expected = step1;
233 };
234 testTranslateServiceToRoutes = {
235 expr = lib.clicks.nginx.http.internal.translateServiceToRoutes step1;
236 expected = step2;
237 };
238 testTranslateRoutesDagToList = {
239 expr = lib.clicks.nginx.http.internal.translateRoutesDagToList step2;
240 expected = step3;
241 };
242 testUnwrapHeader = {
243 expr = lib.clicks.nginx.http.internal.unwrapHeaders step3;
244 expected = step4;
245 };
246 testTranslateRoutesToLocations = {
247 expr = lib.clicks.nginx.http.internal.translateRoutesToLocations step4;
248 expected = step5;
249 };
250 testSetLocationPriorities = {
251 expr = lib.clicks.nginx.http.internal.setLocationPriorities step5;
252 expected = step6;
253 };
254 testAddListenDefaults = {
255 expr = lib.clicks.nginx.http.internal.addListenDefaults step6;
256 expected = step7;
257 };
258}