Add proxy entry for today's garfield comic

This commit is contained in:
Erwin Boskma 2024-06-13 15:11:08 +02:00
parent 762b6c45cc
commit 3625092420
Signed by: erwin
SSH key fingerprint: SHA256:/Wk1WZdLg+vQHs3in9qq7PsIp8SMzwGSk/RLZ5zPuZk
3 changed files with 72 additions and 1 deletions

View file

@ -1,5 +1,10 @@
{ self, ... }: { self, ... }:
{ modulesPath, lib, ... }: {
pkgs,
modulesPath,
lib,
...
}:
{ {
imports = [ imports = [
"${modulesPath}/profiles/qemu-guest.nix" "${modulesPath}/profiles/qemu-guest.nix"
@ -118,6 +123,22 @@
enable = true; enable = true;
permitCertUid = "caddy"; permitCertUid = "caddy";
}; };
caddy = {
virtualHosts = {
"garfield.datarift.nl" =
let
webRoot = pkgs.writeTextDir "index.html" (builtins.readFile ../proxy/index.html);
in
{
extraConfig = ''
root * ${webRoot}
rewrite * /index.html
file_server
'';
};
};
};
}; };
security = { security = {

View file

@ -104,6 +104,28 @@
sudo.enable = false; sudo.enable = false;
}; };
services = {
caddy = {
virtualHosts = {
"garfield.datarift.nl" =
let
webRoot = pkgs.writeTextDir "index.html" (builtins.readFile ./index.html);
in
{
extraConfig = ''
root * ${webRoot}
rewrite * /index.html
file_server
tls {
dns cloudflare {env.CF_API_TOKEN}
resolvers 1.1.1.1
}
'';
};
};
};
};
sops.defaultSopsFile = ./secrets.yaml; sops.defaultSopsFile = ./secrets.yaml;
sops.secrets = { sops.secrets = {
caddy-env = { }; caddy-env = { };

28
machines/proxy/index.html Normal file
View file

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Today's Garfield</title>
<script>
document.addEventListener("DOMContentLoaded", () => {
const date = new Date();
const year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
if (month < 10) {
month = "0" + month;
}
if (day < 10) {
day = "0" + day;
}
const url = `https://www.gocomics.com/garfield/${year}/${month}/${day}/`;
console.log(`Redirecting to ${url}`);
location.href = url;
});
</script>
<meta charset="utf-8" />
</head>
<body></body>
</html>