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