From b4ec6d16b3c2e2cd5729af6da6b09e9248b4a038 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Tue, 27 Feb 2024 13:37:46 +0100 Subject: [PATCH] add redirects to config --- .../dda/c4k_website/website/website_internal.cljc | 15 ++++++++++----- .../website/website_internal_test.cljc | 7 ++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/cljc/dda/c4k_website/website/website_internal.cljc b/src/main/cljc/dda/c4k_website/website/website_internal.cljc index fc26cf0..df6f0a5 100644 --- a/src/main/cljc/dda/c4k_website/website/website_internal.cljc +++ b/src/main/cljc/dda/c4k_website/website/website_internal.cljc @@ -91,7 +91,7 @@ (str/join (str "\n" (str/join (take indent (repeat " ")))) (map - #(str "rewrite ^" (first %1) "$ " (second %1) " permanent;") + #(str "rewrite ^" (first %1) "\\$ " (second %1) " permanent;") redirects)))) @@ -101,12 +101,17 @@ name (replace-dots-by-minus unique-name)] (-> (yaml/load-as-edn "website/nginx-configmap.yaml") - (assoc-in [:metadata :namespace] name) (replace-all-matching-substrings-beginning-with "NAME" name) - (#(assoc-in % - [:data :website.conf] + (#(assoc-in % [:data :website.conf] (str/replace - (-> % :data :website.conf) #"FQDN" (str (str/join " " fqdns) ";"))))))) + (-> % :data :website.conf) + #"FQDN" + (str (str/join " " fqdns) ";")))) + (#(assoc-in % [:data :website.conf] + (str/replace + (-> % :data :website.conf) + #"REDIRECTS" + (generate-redirects config 2))))))) (defn-spec generate-website-build-secret pred/map-or-seq? diff --git a/src/test/cljc/dda/c4k_website/website/website_internal_test.cljc b/src/test/cljc/dda/c4k_website/website/website_internal_test.cljc index e3cff63..ca69ce9 100644 --- a/src/test/cljc/dda/c4k_website/website/website_internal_test.cljc +++ b/src/test/cljc/dda/c4k_website/website/website_internal_test.cljc @@ -18,7 +18,7 @@ (st/instrument `cut/generate-nginx-service) (deftest should-generate-redirects - (is (= "rewrite ^/products.html$ /offer.html permanent;\n rewrite ^/one-more$ /redirect permanent;" + (is (= "rewrite ^/products.html\\$ /offer.html permanent;\n rewrite ^/one-more\\$ /redirect permanent;" (cut/generate-redirects {:issuer "staging" :build-cpu-request "500m" :build-cpu-limit "1700m" @@ -80,7 +80,7 @@ :metadata :namespace)))) (deftest should-generate-nginx-configmap-website - (is (= "server {\n listen 80 default_server;\n listen [::]:80 default_server;\n server_name test.de www.test.de test-it.de www.test-it.de;\n add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload'; \n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options nosniff;\n add_header Referrer-Policy \"strict-origin\";\n # add_header Permissions-Policy \"permissions here\";\n root /var/www/html/website/;\n index index.html;\n location / {\n try_files $uri $uri/ /index.html =404;\n }\n # redirects\n REDIRECTS\n}\n" + (is (= "server {\n listen 80 default_server;\n listen [::]:80 default_server;\n server_name test.de www.test.de test-it.de www.test-it.de;\n add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload'; \n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options nosniff;\n add_header Referrer-Policy \"strict-origin\";\n # add_header Permissions-Policy \"permissions here\";\n root /var/www/html/website/;\n index index.html;\n location / {\n try_files $uri $uri/ /index.html =404;\n }\n # redirects\n rewrite ^/products.html$ /offer.html permanent;\n rewrite ^/one-more$ /redirect permanent;\n}\n" (:website.conf (:data (cut/generate-nginx-configmap {:issuer "staging" :build-cpu-request "500m" :build-cpu-limit "1700m" @@ -88,7 +88,8 @@ :build-memory-limit "512Mi" :volume-size "3" :unique-name "test.io", - :redirects [], + :redirects [["/products.html", "/offer.html"] + ["/one-more", "/redirect"]] :forgejo-host "gitea.evilorg", :forgejo-repo "none", :branchname "mablain",