about summary refs log tree commit diff
path: root/bundles/lhost
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/lhost')
-rw-r--r--bundles/lhost/files/Caddyfile11
-rw-r--r--bundles/lhost/files/cron_job3
-rwxr-xr-xbundles/lhost/files/lhost-prune12
-rw-r--r--bundles/lhost/items.py4
4 files changed, 25 insertions, 5 deletions
diff --git a/bundles/lhost/files/Caddyfile b/bundles/lhost/files/Caddyfile
index 497ef30..0e865a0 100644
--- a/bundles/lhost/files/Caddyfile
+++ b/bundles/lhost/files/Caddyfile
@@ -20,6 +20,17 @@ http:// {
 		}
 	}
 
+	# enable cors
+	header {
+		Access-Control-Allow-Headers *
+		Access-Control-Allow-Methods *
+		Access-Control-Allow-Origin *
+	}
+	@options {
+		method OPTIONS
+	}
+	respond @options 204
+
 	# catch all
 	respond 404
 
diff --git a/bundles/lhost/files/cron_job b/bundles/lhost/files/cron_job
new file mode 100644
index 0000000..7459661
--- /dev/null
+++ b/bundles/lhost/files/cron_job
@@ -0,0 +1,3 @@
+#!/bin/sh
+set -eu
+exec lhost-prune >/dev/null 2>&1
diff --git a/bundles/lhost/files/lhost-prune b/bundles/lhost/files/lhost-prune
index 8788941..bf1a56a 100755
--- a/bundles/lhost/files/lhost-prune
+++ b/bundles/lhost/files/lhost-prune
@@ -1,10 +1,11 @@
 #!/bin/sh
 set -eu
+[ -n "${DEBUG:-}" ] && set -x
 
 main() {
-	local dryrun=$(test -n "${DRYRUN:-}" && printf echo)
+	local dryrun=$([ -n "${DRYRUN:-}" ] && printf echo)
 	local root=${ROOT:-/var/www/lhost}
-	local maxage=${MAXAGE:-30}
+	local maxage=${MAXAGE:-"+30"}
 
 	find ${root} \
 		-type f \
@@ -12,9 +13,10 @@ main() {
 		-not \( \
 		-name 'Caddyfile' -or \
 		-name '.keep' -or \
-		-name "$(cat ${root}/.keep)" \
 		\) \
-		-exec ${dryrun} rm -rv {} +
+		-print |
+		grep -v "$(cat "${root}/.keep")" |
+		xargs -I% ${dryrun} rm -rv '%'
 }
 
-main >/dev/null 2>&1
+main
diff --git a/bundles/lhost/items.py b/bundles/lhost/items.py
index ac2e428..41b0c91 100644
--- a/bundles/lhost/items.py
+++ b/bundles/lhost/items.py
@@ -18,7 +18,11 @@ files = {
     "/etc/s6-rc/lhost.conf": {
         "content_type": "mako",
     },
+    "/usr/bin/lhost-prune": {
+        "mode": "0755",
+    },
     "/etc/periodic/weekly/lhost-prune": {
         "mode": "0755",
+        "source": "cron_job",
     },
 }