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; '';