From f4abc22f9ca35bb7674ffabe4f68602fd1c9bf7f Mon Sep 17 00:00:00 2001 From: RGBCube Date: Mon, 26 Feb 2024 14:15:21 +0300 Subject: [PATCH] CORS!!!! --- hosts/cube/site.nix | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/hosts/cube/site.nix b/hosts/cube/site.nix index 3e0c8fc..7985048 100644 --- a/hosts/cube/site.nix +++ b/hosts/cube/site.nix @@ -10,12 +10,30 @@ let locations."= /404.html".extraConfig = "internal;"; }; in serverSystemConfiguration { + services.nginx.appendHttpConfig = '' + map $http_origin $allow_origin { + ~^https://.+\.rgbcu.be$ $http_origin; + } + + map $http_origin $allow_methods { + ~^https://.+\.rgbcu.be$ "GET, HEAD, OPTIONS"; + } + ''; + services.nginx.virtualHosts.${domain} = ulib.recursiveUpdateAll [ (sslTemplate domain) notFoundLocationConfig { root = "${path}"; - locations."/".tryFiles = "$uri $uri.html $uri/index.html =404"; + locations."/".tryFiles = "$uri $uri.html $uri/index.html =404"; + locations."/assets/".extraConfig = '' - add_header Access-Control-Allow-Origin *.rgbcu.be; + add_header Access-Control-Allow-Origin $allow_origin; + add_header Access-Control-Allow-Methods $allow_methods; + + if ($request_method = OPTIONS) { + add_header Content-Type text/plain; + add_header Content-Length 0; + return 204; + } expires 24h; '';