From 6f2f488db443e619b72d2cf5d4fbff11f8eef578 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Tue, 5 Mar 2024 07:49:24 +0100 Subject: static.nomath.org: add cors --- apps/static-website/appspec.nix | 4 ++++ apps/static-website/module.nix | 15 +++++++++++---- systems/system1/configuration.nix | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/static-website/appspec.nix b/apps/static-website/appspec.nix index c7e919e..e1b41c0 100644 --- a/apps/static-website/appspec.nix +++ b/apps/static-website/appspec.nix @@ -2,6 +2,10 @@ description = "static website"; endOfLife = null; options = { + cors = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + }; domain = lib.mkOption { description = "Domain of the website"; type = fysilib.types.fqdn; diff --git a/apps/static-website/module.nix b/apps/static-website/module.nix index 659dfad..32fed09 100644 --- a/apps/static-website/module.nix +++ b/apps/static-website/module.nix @@ -1,4 +1,11 @@ -{ appConfig, ... }: { - services.nginx.enable = true; - services.nginx.virtualHosts.${appConfig.domain}.locations."/".root = appConfig.root; -} +{ appConfig, lib, ... }: lib.mkMerge [ + { + services.nginx.enable = true; + services.nginx.virtualHosts.${appConfig.domain}.locations."/".root = appConfig.root; + } + (lib.mkIf (appConfig.cors != null) { + services.nginx.virtualHosts.${appConfig.domain}.locations."/".extraConfig = '' + add_header 'Access-Control-Allow-Origin' '${appConfig.cors}'; + ''; + }) +] diff --git a/systems/system1/configuration.nix b/systems/system1/configuration.nix index 13fa8a5..79fc17e 100644 --- a/systems/system1/configuration.nix +++ b/systems/system1/configuration.nix @@ -32,6 +32,7 @@ } # enable static website "static.nomath.org" { + fysiweb-apps.public.static-website."static-nomath-org".cors = "*"; fysiweb-apps.public.static-website."static-nomath-org".domain = "static.nomath.org"; fysiweb-apps.public.static-website."static-nomath-org".root = "/var/lib/abuilder/static-nomath-org/main"; } -- cgit v1.2.3