From 42f427361dfb10596bcfc8dc25c5c38d12b310d1 Mon Sep 17 00:00:00 2001 From: NielsAD Date: Sun, 16 Sep 2018 12:30:45 +0200 Subject: [PATCH] Asynchronous js loading --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++++ public/index.html | 2 +- public/script.js | 9 ++++++--- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index da18637..04364d0 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,53 @@ Usage #### Example `./autoindex -a=":4000" -i=5m -d=/tmp/autoindex.db -cached -r=/mnt/storage` + + +Behind nginx +------------ + +Example configuration for running `autoindex` behind an `nginx` proxy. + +``` +upstream autoindex { + server 127.0.0.1:4000; + keepalive 8; +} + +map $request_uri $request_basename { + ~/(?[^/?]*)(?:\?|$) $captured_request_basename; +} + +map $request_uri $idx_path { + ~/(?[^?]*)(?\?.*)?$ $captured_request_path/$cap$ +} + +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name _; + + root /opt/autoindex/public; + + location / { + rewrite ^/(.*)/$ /$1 permanent; + try_files $uri /index.html; + expires 1y; + } + + location = /index.html { + http2_push /idx/$idx_path; + expires 1d; + } + + location ^~ /dl/ { + limit_rate 1m; + add_header Content-Disposition 'attachment; filename="$request_basename"'; + add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive"; + } + + location ~ ^(/idx/|/urllist.txt) { + proxy_pass https://autoindex; + } +} +``` diff --git a/public/index.html b/public/index.html index 75177d7..81e9bca 100644 --- a/public/index.html +++ b/public/index.html @@ -9,7 +9,7 @@ Archive - toom.io - +
diff --git a/public/script.js b/public/script.js index f89f3ee..dc1a146 100644 --- a/public/script.js +++ b/public/script.js @@ -85,8 +85,7 @@ function setPath(crumbs, files, q, path, query) { req.open("GET", "/idx/" + path + query, true); req.send(); } - -document.addEventListener("DOMContentLoaded", function() { +function onLoad() { const path = document.getElementById("path"); const files = document.getElementById("files"); const search = document.getElementById("search"); @@ -102,4 +101,8 @@ document.addEventListener("DOMContentLoaded", function() { const s = q.value ? "?r=1&q=" + encodeURIComponent(q.value) : ""; setPath(path, files, q, document.location.pathname, s); }); -}); +} +if (document.readyState === "loading") + document.addEventListener("DOMContentLoaded", onLoad); +else + onLoad();