commit 7885d54583b981586dc4c36b602fcc9766959cd0 Author: Jake Howard Date: Sun Mar 3 17:45:52 2024 +0000 Commit something which vaguely works diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cdb41f8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM alpine:3.19 + +RUN apk add --no-cache nginx gettext nginx-mod-http-brotli nginx-mod-http-dav-ext nginx-mod-http-js + +RUN mkdir -p /run/nginx +RUN htpasswd -b -c /etc/nginx/.htpasswd user password + +COPY ./nginx.conf /etc/nginx/http.d/default.conf +COPY ./slides.js /etc/nginx/slides.js +COPY ./docker-entrypoint.sh /docker-entrypoint.sh + +ENV PUID 1000 + +EXPOSE 80 + +STOPSIGNAL SIGKILL + +CMD ["/docker-entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ceb5c13 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: "2.3" + +services: + slides: + build: + context: . + volumes: + - ".:/srv" + ports: + - "80:80" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..483173f --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +set -e + +# Update nginx user id +deluser nginx +adduser -u $PUID -D nginx + +exec nginx -g "daemon off;" diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..c0afa96 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,59 @@ +server { + listen 80; + root /srv; + + access_log /dev/stdout; + error_log /dev/stderr; + + keepalive_timeout 65; + sendfile_max_chunk 1m; + + gzip_static off; + gzip on; + gzip_types *; + + # brotli + brotli on; + brotli_static on; + + # IP detection + set_real_ip_from 0.0.0.0/0; + real_ip_header X-Forwarded-For; + + index index.html; + try_files $uri $uri/ =404; + + error_page 403 =404 /404.html; + + # Kick malicious clients sooner + client_header_timeout 10s; + client_body_timeout 10s; + client_max_body_size 128k; + reset_timedout_connection on; + + # Expose WebDAV on a sub-path + location /.dav/ { + alias /srv/; + + auth_basic_user_file /etc/nginx/.htpasswd; + auth_basic "Restricted"; + + dav_methods PUT DELETE MKCOL COPY MOVE; + dav_ext_methods PROPFIND OPTIONS; + min_delete_depth 1; + + client_body_temp_path /tmp; + create_full_put_path on; + } + + # Healthcheck endpoint + location /.ping { + access_log off; + return 200; + } + + js_import slides.js; + location = /sitemap.xml { + js_content slides.sitemap; + } +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..39a2b6e --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} diff --git a/slides.js b/slides.js new file mode 100644 index 0000000..80d56f7 --- /dev/null +++ b/slides.js @@ -0,0 +1,25 @@ +const fs = require("fs"); + +function sitemap(r) { + const directories = fs.readdirSync("/srv") + .map(f => [f, fs.statSync(`/srv/${f}`)]) + .filter(d => d[1].isDirectory()) + .map(d => { + const directoryName= d[0]; + const stats = d[1]; + const modifiedTime = new Date(stats.mtime); + return `https://slides.theorangeone.net/${directoryName}/${modifiedTime.toISOString().split("T")[0]}`; + }); + + const sitemapData = ` + + ${directories.join('')} + + `.replace("\n", ""); + + r.headersOut["content-type"] = "application/xml"; + + r.return(200, sitemapData); +} + +export default {sitemap};