0010i started setting up my droplet today.
0012here's a log.
0014i created a droplet on digital ocean today.
00161 GB Memory / 25 GB Disk + 10 GB / SFO3 - Docker 23.0.6 on Ubuntu 22.04
0018I mounted the storage separately because i can easily move to another droplet if i choose.
0020with docker on it, i can just try a bunch of languages and images.
0022after getting it set up with ssh by public key from my mac mini at home, i logged in.
0024the lockfile for apt-get was broken on the first install.
0026i tried to remove the lock file and retry. no dice. i restarted the machine and it was fine.
0028the first real tool i installed was vs code server. it made it super easy to just drive this machine like it's my local machine.
0030after that, opened up http and https with ufw
0038i wanted a vert simple way to serve something and make sure i could reach the device from the internet, not just over ssh
0040i installed bun and made a very simple http handler.
0063```
0064Bun.serve({
0065 port: 80, // defaults to $BUN_PORT, $PORT, $NODE_PORT otherwise 3000
0066 hostname: "0.0.0.0", // defaults to "0.0.0.0"
0067 fetch(req) {
0068 return new Response("h e l l o w o r l d");
0069 },
0070 });
0072```
0074started it. i couldn't hit it from the internet.
0076digital ocean required that i also create a firewall rule
0078so i did. 22, 80, 443
0080hit it from the internet and got a response πͺ
0082great. now i needed to set up dns.
0084i went to my trusty https://freedns.afraid.org/
0086set the old one that was pointing to my home server to the droplet's address
0088it took some time to propagate.
0090from chrome though, all i was getting was ERR_CONNECTION_REFUSED
0092i tried to curl it from my local machine
0099i got back the expected response.
0101so what is going on with chrome.
0103i went to the network tab and copied the request as curl.
0105i decided that it might be something a browser call is enforcing, so i should try all the same everything (cookies headers etc) from another spot.
0107```
0108β ~ curl 'https://zapplebee.prettybirdserver.com/' \
0109 -H 'Upgrade-Insecure-Requests: 1' \
0110 -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' \
0111 -H 'sec-ch-ua: "Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"' \
0112 -H 'sec-ch-ua-mobile: ?0' \
0113 -H 'sec-ch-ua-platform: "macOS"' \
0114 --compressed
0115curl: (7) Failed to connect to zapplebee.prettybirdserver.com port 443: Connection refused
0117```
0119i realized that chrome was trying to reach the https port 443. on which i had nothing running yet
0121but it was hitting the machine
0123just not in a way that i could see.
0125i could now set up certbot.
0131i dont really have a proxy or load balancer decided on yet, so i was going to just use certbot without auto configuration.
0133https://www.digitalocean.com/community/tutorials/how-to-use-certbot-standalone-mode-to-retrieve-let-s-encrypt-ssl-certificates-on-ubuntu-20-04
0135i created the certs manually
0137```
0138certbot certonly --standalone -d zapplebee.prettybirdserver.com
0140...
0141Successfully received certificate.
0142Certificate is saved at: /etc/letsencrypt/live/zapplebee.prettybirdserver.com/fullchain.pem
0143Key is saved at: /etc/letsencrypt/live/zapplebee.prettybirdserver.com/privkey.pem
0144This certificate expires on 2024-04-12.
0146```
0148once i set up a service that needs to restart on renewal i can update this line in the conf file, `/etc/letsencrypt/renewal/zapplebee.prettybirdserver.com.conf`
0158```
0159Bun.serve({
0160 port: 443,
0161 hostname: "0.0.0.0",
0162 fetch(req) {
0163 return new Response("h e l l o w o r l d");
0164 },
0165 tls: {
0166 cert: Bun.file(
0167 "/etc/letsencrypt/live/zapplebee.prettybirdserver.com/cert.pem",
0168 ),
0169 key: Bun.file(
0170 "/etc/letsencrypt/live/zapplebee.prettybirdserver.com/privkey.pem",
0171 ),
0172 },
0173});
0174```
0178```
0180Bun.serve({
0181 port: 443,
0182 hostname: "0.0.0.0",
0183 fetch(req) {
0184 return new Response("h e l l o w o r l d");
0185 },
0186 tls: {
0187 cert: Bun.file(
0188 "/etc/letsencrypt/live/zapplebee.prettybirdserver.com/cert.pem",
0189 ),
0190 key: Bun.file(
0191 "/etc/letsencrypt/live/zapplebee.prettybirdserver.com/privkey.pem",
0192 ),
0193 },
0194});
0196Bun.serve({
0197 port: 80,
0198 hostname: "0.0.0.0",
0199 fetch(req) {
0200 return Response.redirect(`${req.url.replace(/^http:/gi, "https:")}`, 302);
0201 },
0202});
0204```
0206https://regexr.com/ is my trusty regex helper site.
0208this was substantially easier than any proxy config i have ever used.
0210it's alive.
0212```
0214β ~ curl zapplebee.prettybirdserver.com -L --verbose
0215* Trying 159.223.202.91:80...
0216* Connected to zapplebee.prettybirdserver.com (159.223.202.91) port 80 (#0)
0217> GET / HTTP/1.1
0218> Host: zapplebee.prettybirdserver.com
0219> User-Agent: curl/7.77.0
0220> Accept: */*
0221>
0222* Mark bundle as not supporting multiuse
0223< HTTP/1.1 302 Found
0224< Location: https://zapplebee.prettybirdserver.com/
0225< Date: Sat, 13 Jan 2024 03:08:35 GMT
0226< Content-Length: 0
0227<
0228* Connection #0 to host zapplebee.prettybirdserver.com left intact
0229* Issue another request to this URL: 'https://zapplebee.prettybirdserver.com/'
0230* Trying 159.223.202.91:443...
0231* Connected to zapplebee.prettybirdserver.com (159.223.202.91) port 443 (#1)
0232* ALPN, offering h2
0233* ALPN, offering http/1.1
0234* successfully set certificate verify locations:
0235* CAfile: /etc/ssl/cert.pem
0236* CApath: none
0237* TLSv1.2 (OUT), TLS handshake, Client hello (1):
0238* TLSv1.2 (IN), TLS handshake, Server hello (2):
0239* TLSv1.2 (IN), TLS handshake, Certificate (11):
0240* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
0241* TLSv1.2 (IN), TLS handshake, Server finished (14):
0242* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
0243* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
0244* TLSv1.2 (OUT), TLS handshake, Finished (20):
0245* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
0246* TLSv1.2 (IN), TLS handshake, Finished (20):
0247* SSL connection using TLSv1.2 / ECDHE-ECDSA-CHACHA20-POLY1305
0248* ALPN, server did not agree to a protocol
0249* Server certificate:
0250* subject: CN=zapplebee.prettybirdserver.com
0251* start date: Jan 13 01:40:23 2024 GMT
0252* expire date: Apr 12 01:40:22 2024 GMT
0253* subjectAltName: host "zapplebee.prettybirdserver.com" matched cert's "zapplebee.prettybirdserver.com"
0254* issuer: C=US; O=Let's Encrypt; CN=R3
0255* SSL certificate verify ok.
0256> GET / HTTP/1.1
0257> Host: zapplebee.prettybirdserver.com
0258> User-Agent: curl/7.77.0
0259> Accept: */*
0260>
0261* Mark bundle as not supporting multiuse
0262< HTTP/1.1 200 OK
0263< content-type: text/plain;charset=utf-8
0264< Date: Sat, 13 Jan 2024 03:08:35 GMT
0265< Content-Length: 21
0266<
0267* Connection #1 to host zapplebee.prettybirdserver.com left intact
0268h e l l o w o r l d%
0270```
0272the first bug was discovered.
0274by default, bun did not read the encoding of the file that was read from disk.
0276i guess i assumed it would.
0278my good friend Ryan Rampersad https://twitter.com/ryanmr pointed out that the unicode characters where buggy.
0280i looked and saw that the server was responding with a `Content-type` header of `text/markdown`.
0282Bun had identified this but did not automatically set the additional encoding information.
0284it was changes to `text/markdown; charset=utf-8`
0288now it works as expected.
0290i need a way to run this locally that ignores the certs
0292the way it will work is based on the NODE_ENV, i'll create the configuration differently.
0294though i don't love that i am going to bake this directly into the entrypoint file, the app is still very simple and it's okay. the goal is to make some thing that can be changed.
0296in the .bashrc file i'll export the NODE_ENV.
0302that way, anytime i am running something on this machine it will automatically be set.
0304right now the service is just being run in the background.
0310While bun does support a watch mode, i dont really want to think about memory leaks yet so i am just going to make a handy alias to stop and restart it.
0312to find the running process in the background, I'm running
0314```
0315ss -lptn 'sport = :80'
0316State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
0317LISTEN 0 512 0.0.0.0:80 0.0.0.0:* users:(("bun",pid=1562,fd=14))
0318```
0320while this is good, i'm going to need to trim that output so i can get just the process id and kill it
0322i can use `awk` for this.
0324```
0325ss -lptn 'sport = :80' | awk 'NR > 1 {print $6}'
0326users:(("bun",pid=1562,fd=14))
0328```
0330this skips the first line, the table headers, and then takes the sixth column value.
0332still not quite just the process id.
0334a couple cuts will do the trick
0336```
0337ss -lptn 'sport = :80' | awk 'NR > 1 {print $6}' | cut -d= -f2 | cut -d, -f1
03381562
0339```
0341this gives me just the process id of the server that is listening on port 80. i could have used the https port 443 instead but this is fine since it has to serve both for the redirects.
0343next i have to pass that var into a `kill` command.
0345I can do that with a command substitution.
0347```
0348kill $(ss -lptn 'sport = :80' | awk 'NR > 1 {print $6}' | cut -d= -f2 | cut -d, -f1)
0349```
0353```
0355kill $(ss -lptn 'sport = :80' | awk 'NR > 1 {print $6}' | cut -d= -f2 | cut -d, -f1) & bun /mnt/volume_sfo3_01/apps/helloworld/index.ts &
0357```
0361```
0362alias restartbun="kill $(ss -lptn 'sport = :80' | awk 'NR > 1 {print $6}' | cut -d= -f2 | cut -d, -f1) & bun /mnt/volume_sfo3_01/apps/helloworld/index.ts &"
0363```
0365this gives me a couple advantages right now.
03671. there's no auto deploy. i have to pull from git or change the files on the server and restart. this will let me make a mess of things and not have an auto watcher restarting the server if it's not in a good state.
03682. it's based on what port is exposed, so if i change the actual edge listener to a proxy or something, i can restart it with pretty much the same command.
0370okay, now i can finally set up the application code to serve certs if we're in production mode.
0372```
0374const PRODUCTION_CONFIG = {
0375 port: 443,
0376 tls: {
0377 cert: Bun.file(
0378 "/etc/letsencrypt/live/zapplebee.prettybirdserver.com/cert.pem",
0379 ),
0380 key: Bun.file(
0381 "/etc/letsencrypt/live/zapplebee.prettybirdserver.com/privkey.pem",
0382 ),
0383 },
0384} as const;
0386const DEV_CONFIG = {
0387 port: 3100
0388} as const;
0390const IS_PRODUCTON = process.env.NODE_ENV === 'production';
0392const LIVE_CONFIG = IS_PRODUCTON ? PRODUCTION_CONFIG : DEV_CONFIG;
0394Bun.serve({
0396 hostname: "0.0.0.0",
0397 fetch(req) {
0398 return new Response(Bun.file("/mnt/volume_sfo3_01/apps/notes/setting-up-the-droplet.md"), {
0399 headers: {
0400 'Content-type': 'text/markdown; charset=utf-8'
0401 }
0402 });
0403 },
0404 ...LIVE_CONFIG
0405});
0408if(IS_PRODUCTON) {
0409 // no need to serve the redirects if we're not in prod
0410 Bun.serve({
0411 port: 80,
0412 hostname: "0.0.0.0",
0413 fetch(req) {
0414 return Response.redirect(`${req.url.replace(/^http:/gi, "https:")}`, 302);
0415 },
0416 });
0418}
0421```
0431okay now that i have a dev mode i can start to actually add some features to this thing.
0433first of all, i would prefer some minimal styling...
0435and i do mean minimal.
0437and to actually serve this as html
0439so far i don't have any dependencies and it might be good to keep it that way for a while.
0441bun gives me a lot out of the box and would like to keep dependencies to a minimum
0443first, i'll read up all the markdown paths.
0445```
0446export async function getFilePaths(): Promise<Array<string>> {
0447 const glob = new Glob("*.md");
0449 const filepaths: Array<string> = [];
0451 for await (const file of glob.scan(NOTES_DIRECTORY)) {
0452 filepaths.push(`${NOTES_DIRECTORY}${file}`);
0453 }
0455 return filepaths;
0456}
0458```
0462```
0463export async function getAsHtml(): Promise<string> {
0464 const filepaths = await getFilePaths();
0465 const files = filepaths.map((e) => Bun.file(e));
0467 const fileContents = await Promise.all(files.map((e) => e.text()));
0469 const rawBody = fileContents.join("\n---\n");
0471 return `<!DOCTYPE html>
0472<html><body><style>* {background-color: black; color: green;}</style><pre>${Bun.escapeHTML(rawBody)}</pre></body></html>`;
0473}
0475```
0477at last i'll import it in the index.
0479since i want this to fail early, ie at start up, i'll use bun's macro capability to do it.
0485this runs the getting and escaping of the files at start up and in-lines the result into the AST.
0489not super useful now since i am not bundling, but an appropriate use of a macro
0491i also added gzip it was very simple.
0493```
0494const HTML_CONTENT = await getAsHtml();
0496const data = Buffer.from(HTML_CONTENT);
0497const compressed = Bun.gzipSync(data);
0499Bun.serve({
0500 hostname: "0.0.0.0",
0501 fetch(req) {
0502 return new Response(compressed, {
0503 headers: {
0504 "Content-Encoding": "gzip",
0505 "Content-type": "text/html; charset=utf-8",
0506 },
0507 });
0508 },
0509 ...LIVE_CONFIG,
0510});
0512```
0514although I do really like this just one long file method,
0515there's something not quite right about it.
0517and that's the ability to link to a specific piece of content.
0519I think that the best course of action is just to create id anchors for every line.
0521then one can easily deep link directly to a place on the page.
0523there's a couple things that need to happen in order for that to work as expected.
05251. i need to split the file line by line.
05262. map those back together with a link at the start of the line.
05273. create a line count column on the left site that has a link to the line itself.
0529as i was doing this i thought i might need to start to tag where i am in the git repo so that if someone (me) wanted to follow along in the future, it would be easy
0531```
0532git show-ref
05333590fff8df7ecfcebd7f9379637977403549f62e refs/heads/main
05343590fff8df7ecfcebd7f9379637977403549f62e refs/remotes/origin/HEAD
05353590fff8df7ecfcebd7f9379637977403549f62e refs/remotes/origin/main
0536```
0538i sure could just let people do a git blame. but they might just be reading this as plain text.
0540a few edits to the html file and bang we we have direct links.
0542i am fighting my a lot of my instincts to not bring in react at this stage as the markup is getting just a bit complex.
0544as my friend ardeshir (https://hachyderm.io/@sepahsalar) said:
0546"Yep, you start adding A π·οΈ s and next thing you know, youβve written a new RSC framework"
0548```
0550export async function getAsHtml(): Promise<string> {
0551 const filepaths = await getFilePaths();
0552 const files = filepaths.map((e) => Bun.file(e));
0553 const fileContents = await Promise.all(files.map((e) => e.text()));
0554 const rawBody = fileContents.join("\n---\n").replaceAll("\r", "");
0555 const escapedBody = Bun.escapeHTML(rawBody);
0556 const bodyLines = escapedBody.split("\n");
0557 const maxCharactersInLineNumber = String(bodyLines.length).length;
0559 return `<!DOCTYPE html>
0560<html><body><style>* {background-color: black; color: #4d9c25;} .line-link {color: #2f5c19;} .space, .line-link { -webkit-user-select: none; -ms-user-select: none; user-select: none;}</style><pre>${bodyLines
0561 .map((line, index) => {
0562 const lineNumber = String(index).padStart(maxCharactersInLineNumber, "0");
0563 const lineId = `line-${lineNumber}`;
0565 return `<span class="line" id="${lineId}"><a class="line-link" href="#${lineId}">${lineNumber}</a><span class="space"> </span><span>${line}</span></span>`;
0566 })
0567 .join("\n")}</pre></body></html>`;
0568}
0571```
0573the next thing i want to do is enable a line wrap mode for mobile.
0575but i dont want the markdown style codeblocks wrap.
0577so i first need to make the codeblocks wrapped in a new node.
0579i'll have to do some refactoring of the page builder.
0581as soon as I change styles in there to a static CSS file, i was already starting to get irritated by the lack of structure in code.
0583there's literally one handler. it should be easy to change, and it is, the hard part is thinking about what I want to change it to.
0585i was really trying defer design decisions because, well, i dont want to think about it too hard.
0587this is supposed to be a fun little project.
0589i guess to keep this as simple as possible, i should just write vanilla css and i really need to vanilla js and just author and host them from a public folder
0591It's time that I actually messed with these Link headers.
0593This should allow the network requests to start as soon as the document loads.
0597That will keep the doc in cache until it used by the page.
0599I need to modify the response that the html request returns
0615added a little magic to the html renderer. not my best code ever. but it does the job until i find a real framework i want to use for this.
0617````
0619export async function getAsHtml(): Promise<string> {
0620 const filepaths = await getFilePaths();
0621 const files = filepaths.map((e) => Bun.file(e));
0622 const fileContents = await Promise.all(files.map((e) => e.text()));
0623 const rawBody = fileContents.join("\n---\n").replaceAll("\r", "");
0624 const escapedBody = Bun.escapeHTML(rawBody);
0625 const bodyLines = escapedBody.split("\n");
0626 const maxCharactersInLineNumber = String(bodyLines.length).length;
0628 let inCodeBlock = false;
0630 return `<!DOCTYPE html>
0631<html><head></head><body><style>@import "/public/main.css";</style><pre>${bodyLines
0632 .map((line, index) => {
0633 const linkedLine = line.replaceAll(
0634 /(https:\/\/[^\s\)]+)/gi,
0635 '<a href="$&">$&</a>'
0636 );
0637 const lineNumber = String(index).padStart(maxCharactersInLineNumber, "0");
0638 const lineId = `line-${lineNumber}`;
0640 const isBackticks = line.trim() === "```";
0642 if (isBackticks) {
0643 inCodeBlock = !inCodeBlock;
0644 }
0646 const inCode = Boolean(inCodeBlock || isBackticks);
0648 return `<div class="line" id="${lineId}"><a class="line-link" href="#${lineId}">${lineNumber}</a><span class="space"> </span><span class="${inCode ? "codeblock" : ""}">${inCode ? line : linkedLine}</span></div>`;
0649 })
0650 .join("\n")}</pre></body></html>`;
0651}
0653````
0664I refactored the render function a little to make it more readable.
0666Broke the massive template string into a few variables and mashed them together.
0668Variable names are free documentation.
0670````
0671export async function getAsHtml(): Promise<string> {
0672 const filepaths = await getFilePaths();
0673 const files = filepaths.map((e) => Bun.file(e));
0674 const fileContents = await Promise.all(files.map((e) => e.text()));
0675 const rawBody = fileContents.join("\n---\n").replaceAll("\r", "");
0676 const escapedBody = Bun.escapeHTML(rawBody);
0677 const bodyLines = escapedBody.split("\n");
0678 const maxCharactersInLineNumber = String(bodyLines.length).length;
0680 let inCodeBlock = false;
0682 const headTags = `
0683<title>zapplebee.prettybirdserver.com</title>
0684<style>@import "/public/main.css";</style>
0685`;
0687 const head = `<!DOCTYPE html>
0688<html><head>${headTags}</head><body><main>`;
0690 const tail = `</main></body></html>`;
0692 const main = bodyLines.map((line, index) => {
0693 const lineNumber = String(index).padStart(maxCharactersInLineNumber, "0");
0694 const lineId = `line-${lineNumber}`;
0696 const isBackticks = line.startsWith("```");
0698 let addCodeBlockOpenTag = false;
0699 let addCodeBlockCloseTag = false;
0701 if (isBackticks && !inCodeBlock) {
0702 addCodeBlockOpenTag = true;
0703 }
0705 if (isBackticks) {
0706 inCodeBlock = !inCodeBlock;
0707 }
0709 if (!inCodeBlock && isBackticks) {
0710 addCodeBlockCloseTag = true;
0711 }
0713 const inCode = Boolean(inCodeBlock || isBackticks);
0715 const lineText = inCode
0716 ? line
0717 : line.replaceAll(/(https:\/\/[^\s\)]+)/gi, '<a href="$&">$&</a>');
0719 const containerOpenTag = addCodeBlockOpenTag
0720 ? `<div class="codeblock-container"><div class="codeblock-wrapper">`
0721 : "";
0723 const openingLineTag = `<div class="line" id="${lineId}">`;
0724 const lineIdxElement = `<a class="line-link" href="#${lineId}">${lineNumber}</a>`;
0725 const lineStrElement = `<span class="${inCode ? "codeblock" : "prose"}">${lineText}</span>`;
0726 const closingLineTag = `</div>`;
0727 const containerCloseTag = addCodeBlockCloseTag ? `</div></div>` : "";
0729 return [
0730 containerOpenTag,
0731 openingLineTag,
0732 lineIdxElement,
0733 lineStrElement,
0734 closingLineTag,
0735 containerCloseTag,
0736 ].join("");
0737 }).join("");
0739 return [head, main, tail].join("");
0740}
0742````
0746```
0747 -moz-text-size-adjust: none;
0748 -webkit-text-size-adjust: none;
0749 text-size-adjust: none;
0750```
0752I could not figure out what was making my fonts all messed up
0753despite the `!important` tag.
0755This is what I get for using somebody else's CSS reset all the time.
0757Finally made the CSS into something i could tolerate.
0758It's interesting how dependant I have become on CSS-in-JS or tailwind
0760This was harder than I remember it being.
0762```
0764:root {
0765 --textwidth: 40ch;
0766 --linenumberwidth: 3ch;
0767 --gapwidth: 2ch;
0768}
0770@media (min-width: 500px) {
0771 :root {
0772 --textwidth: 80ch;
0773 }
0774}
0776* {
0777 padding: 0;
0778 margin: 0;
0779 box-sizing: border-box;
0780 line-height: 1.2rem;
0781 font-size: 16px;
0782 font-weight: 400;
0783 color: #4d9c25;
0784 -moz-text-size-adjust: none;
0785 -webkit-text-size-adjust: none;
0786 text-size-adjust: none;
0787}
0789body {
0790 background-color: black;
0791 display: block;
0792}
0794main {
0795 font-family: monospace;
0796 width: calc(var(--textwidth) + var(--linenumberwidth) + var(--gapwidth));
0797 margin: auto;
0798 display: block;
0799}
0801.line {
0802 display: flex;
0803 flex-direction: row;
0804 gap: var(--gapwidth);
0805}
0806.line-link {
0807 color: #2f5c19;
0808 -webkit-user-select: none;
0809 -ms-user-select: none;
0810 user-select: none;
0811 white-space: pre;
0812 width: var(--linenumberwidth);
0813}
0815.codeblock-container {
0816 width: calc(var(--textwidth) + var(--linenumberwidth) + var(--gapwidth));
0817 overflow-x: auto;
0818 overflow-y: hidden;
0819 background-color: rgb(63, 63, 63);
0820}
0822.codeblock {
0823 color: rgb(215, 246, 152);
0824 white-space: pre;
0825}
0827.prose {
0828 width: var(--textwidth);
0829 white-space: pre-wrap;
0830 overflow-wrap: break-word;
0831}
0833::-webkit-scrollbar {
0834 height: 1rem;
0835 width: 1ch;
0836 background: rgb(63, 63, 63);
0837}
0839::-webkit-scrollbar-thumb {
0840 background: rgb(215, 246, 152);
0841}
0843::-webkit-scrollbar-corner {
0844 background: rgb(63, 63, 63);
0845}
0847```
0849the next thing i am going to have to figure out for this is images.
0851they're tricky for a couple reasons.
08531. the style of this website doesn't really have anything that spans too
0854 much vertical space
08552. they cost bandwidth in a way that the plain text just doesn't.
08563. i am trying to not load and js in the client for performance reasons
0857 if i want to do any tricks to save bandwidth or just allow a peek at the image
0858 that's going to be tough without js
0860I have a bit of an idea
0862I could load like, two lines of the image, and add a button to expand.
0864like this
0866<!-- prettier-ignore-start -->
0868imageurl: an-image.jpg
0869βββββββββββββββββββββββ
0870βββββββββββββββββββββββ
0871βββ click to expand βββ
0874imageurl: an-image.jpg
0875ββββββββββββββββββββββ
0876ββββββββββββββββββββββ
0877ββββββββββββββββββββββ
0878βββ βββββββββ βββββ
0879ββββββββββββββββββββββ
0880β ββββββββββββββ βββ
0881βββ ββββββββββ ββββ
0882ββββ ββββββ
0883ββββββββββββββββββββββ
0884ββββββββββββββββββββββ
0885βββ click to close βββ
0887<!-- prettier-ignore-end -->
0889that could be done with just a checkbox and some custom styles
0891but it wouldn't be very accessible.
0893so far, as strange as the set of this site is, it is rather accessible.
0895though i could bump up the contrast from the bg and the text,
0897there's not a busy menu to navigate through via keyboard.
0899there's no animations.
0901theres' no dynamic loading of content.
0903the other accessibility thing I should do is probably add image roles for the emoji
0907(exactly unlike above...)
0909i would also like a way to be able to add content from my phone.
0911this is meant, in part, as a replacement for _centralized microblogging platform formerly known as twitter_
0912in case you couldn't tell from my typing voice. haha.
0914i tried mastodon, but i just didn't get it or something.
0916so the ability to add content whenever, whereever would be nice.
0918stretch goal would be to add the ability to comment on lines.
0920one of the goals of this site is to practice progressive by incremental improvement of this feed.
0921backwards compatibility too.
0923since right now this is just a giant markdown file,
0924it could obviously be replatformed.
0926the other goal is that all the changes to the site get logged here.
0928think of it as a git log + architecture decision record + readme + bullet journal + social media
0930the simple form of it has let me write almost 1000 lines already!
0932in fact
0934TODO: fix the fact that right now the line number width is fixed to three characters
0936i'd also like some kind of convention for being able to write long form segments that get their own page
0938something like
0959The React Empire
0960I recently read this post from [Cassidy Williams](https://twitter.com/cassidoo) on [being a little disappointed with React](https://blog.cassidoo.co/post/annoyed-at-react/)
0962An awful lot of it resonated with me so I thought I would try to put my own thoughts into words on it.
0964When I was just a little computer boy, there was _no_ good way to write real application code that lived in the browser.
0966It was either a ton of boilerplate `createElement` or JQuery. And while both were really powerful, they required a lot of code to do some pretty plain things by today's standards.
0968And they were imperative, rather than declarative.
0970Meaning instead of indicating how you would want the DOM to look, you were giving instructions about how to mutate the DOM.
0972Eventually, I discovered AngularJS. At this time I was still in my adolescence with real software. So it was an amazing journey to be able to write JavaScript apps by just adding a new script tag from a CDN url.
0974I was still writing apps in Notepad++ (Or maybe it was already Sublime Text by then) and FTPing them to the server.
0976Templates for the way the DOM was described in AngularJS was [based on strings](https://docs.angularjs.org/guide/component#components-as-route-templates) or XHR requests to other HTML documents with custom directives specifically to attach into the AngularJS state and events.
0978This was a huge win for me. I was very tired of creating elements, or homebrewing my own abstractions for creating elements.
0980It did have one weakness though. There wasn't a lot of help to make sure what you were writing would work as expected since the templates were just strings. You kind of just had to run it and make sure that you connected your state and handlers correctly.
0982And I was still writing a lot of code to manage data going up and down the tree.
0984Ultimately, it did still make it much easier to work with. AND I STILL DIDN'T NEED ANYTHING BUT TO UPLOAD THE FILES.
0986I built a lot in AngularJS.
0988At the time I was running a couple PHP servers and with some local databases.
0990I had tried with Java and a few other languages, but as an independently taught dev, it was really hard to go from zero knowledge to a running server.
0992π« figuring out a build toolchain and a compiler when you are still working hard to remember that environmental variables are set per shell.
0993π file makes webpage.
0995It was simple. Simple was King (and still is).
0997Enter React.
0999By now, I was pretty comfortable in my space and had started to experiment with NodeJS.
1001Wouldn't it be cool if the whole stack was the same language? That would make skills I learned in one place make me even stronger. I was still leaning about the language after all (and still am -- it's constantly evolving).
1003I went to a local conference and everyone was talking about React.
1005It was mesmerizing what they could build with a little bit of code. But surely I could never get a foothold into this, I mean that wasn't JS they were writing, right?
1007Yes but no.
1009JSX was transformative. Despite it being just a syntax over a `createElement` function, it totally changes the way that one could reason about the DOM tree.
1011It was a good abstraction. It made the important information very visible and made the irrelevant (read as boilerplate) almost disappear.
1013The transformation that it enabled in reasoning with templates in JS also required another transformation. Source JSX -> JavaScript ready for the browser.
1015Today, there is a lot more in the ecosystem that could help you do this kind of transform. At the time there really wasn't, and even if there was I would don't think I could set that up from scratch at the time. Even by following step-by-step instructions.
1017The real magic, was that React also published `create-react-app`. An all-things-included bundler, application scaffold, example application that could easily start to grow from a single page to whatever you wanted it to be -- all while hiding the magic that transformed JSX to JS.
1019A person could get addicted to the ergonomics of the framework before ever having to think about the how.
1021Eventually, like all computer people, I became too curious for my own good and ejected a React App.
1023Ejecting a `create-react-app` would take all the behind-the-scenes magic that was happening and plop it into your work directory.
1025I couldn't get enough -- webpack, babel, the whole thing. I learned about ASTs, I learned about compilers. It was a magical time of growth for me. It didn't hurt that at the time I was working at a newish job where the team's ethic was "let the people focus".
1027Despite all this being in front of me, it would still take a ton to learn before I could really effect change with that configuration.
1029And while I was figuring that out, my app would still just build and run. **The app still felt simple**. I was never more productive in my life.
1031Then came hooks.
1033We no longer had to utilize so many language features to interact with the state and the DOM. In fact we barely had to learn about the framework and its lifecycle to be able to write code for it.
1035An even better refinement on the abstraction. A truly good abstraction should enable you to look at a piece of code and see what its intent is.
1041Even if you've never seen JavaScript, you may be able to reason about that.
1043The patterns let you think about what you're doing. Not what the framework is doing.
1045---
1047There is unquestionably a new age for React. It's not just React Server Components. It's a new world that it lives in.
1049The primary, suggested. ways to start a React project is a tool is not maintained as side-by-side with React itself.
1053React is no longer suggesting that you start with the simplest way to build and deploy and gradually add more complexity. Instead, you get all that complexity on day one.
1055---
1057Let's take Next as the focal point of the rest of this discussion. Because, like it or not, it is become a defacto _next_ step.
1059We now have must specify a boundry about where our components can run.
1065Meaning that we have to constantly think about if a piece of code has access to the DOM in a browser or not.
1067This is all at the file level and not the component level meaning that the handy co-location of mini components gets broken.
1069Routing is based on a filesystem convention, or is it? Next already has two divergent page path conventions.
1071And while it purports to be a full-stack framework, God help you if you want to use something you learned in Node, because sometimes you have access to that API and sometimes you don't.
1073Next, and the other full-stack React frameworks have taken us back to having to think about what the framework is doing. It's a step backwards for development experience in a big way.
1075---
1077Complexity should only ever be added to an application as a decision of the product that is building that application. React has abandoned this mentality.
1079It's still totally possible to build or use React for little pieces of your website, but it's not even approached as a concept in the docs.
1081I still reach for a React app (not `create-react-app`, usually with Vite now) when I want to build something with any amount of rapidity. But less so every day -- and certainly not in the way that it is described in it's documentation.
1083JSX will survive this curve away from the simplicty of a client-side React application. Whether or not React remains king is uncertain. Remember, simplicity is king.
1085as i was writing this post i got a little distracted by making it fancy.
1087but i needed someway to deep link it.
1089i decided that while the hashes did work, it wasn't great for the future if i ever want to capture where traffic is going
1091so instead now i one single line of javascript on the client.
1100while trying to get meta tags working i discovered that there was a certificate problem that was preventing crawlers from getting to the page.
1102so i decided it was time to move from the https://freedns.afraid.org/ subdomain i was using and buy my own
1106i didnt wait long enough for DNS to propagate before trying to set up certs.
1108so now i have to wait an hour
1110```
1112certbot certonly --standalone -d zapplebee.online
1113Saving debug log to /var/log/letsencrypt/letsencrypt.log
1114Requesting a certificate for zapplebee.online
1115An unexpected error occurred:
1116Error creating new order :: too many failed authorizations recently: see https://letsencrypt.org/docs/failed-validation-limit/
1118```
1120once that's passed, i should be able to reinstall new certs.
1122_AND_ then i'll have to figure out all the places i hard coded the domain.
1124it was a good exercise to change it this early for that reason.
1126i bought the domain from https://www.namecheap.com/
1128"bought". I lease the domain from namecheap.
1130that's how a registrar works.
1132I set an A record to point to my droplet
1134A @ 159.223.202.91
1136this points all root level traffic to the droplet.
1138a little sad to leave behind the old prettybird url, but i didn't have really to many rights over it with freedns.
1140I am interested in Bun will allow me to serve multiple domains from a single process.
1142It does include a `hostname` param in the set up for the listener, so i dont see why not.
1144it would just have to be in the same process because they'll both be using ports 80 and 443
1146okay i finally got through some real mess on getting this started in docker.
1147i was mounting the `/etc/letsencrypt/live` into the container so that i could serve certs.
1148but it turns out, that those live certs are symlinked from `/etc/letsencrypt/archive`
1149(with an additional change of name fullchain.pem => fullchain1.pem).
1150after mounted the archive, docker operate on the certs just fine.
1172π Ada's Algorithm: How Lord Byron's Daughter Ada Lovelace Launched the Digital Age
1173I am liking this book a lot.
1175I'm about 2/3rd through it.
1177It's a semi epistolary biography of Ada Lovelace.
1179It focuses on her work with Charles Babbage on his Differential and Analytical Engine.
1181It did spend a little too much time on her family before she really became the focus of the story. Even then it is spending a lot of time with Babbage.
1183Still, I am enjoying it.
1185Reading the letters between the people in the book was a bit of an inspiration for me to start writing this log.
1197I added structured logs to the webserver.
1199The docker agent on the machine already records them to a file
1201this will show them, since i am just running one container
1209```
1210{"log":"{\"hostname\":\"zapplebee.online\",\"ipAddress\":{\"address\":\"βββREDACTEDβββ\",\"family\":\"IPv4\",\"port\":βββREDACTEDβββ},\"level\":\"http\",\"message\":\"GET: /wp-login.php\",\"method\":\"GET\",\"pathname\":\"/wp-login.php\",\"search\":\"\",\"service\":\"helloworld\",\"timestamp\":1705453727099,\"userAgent\":\"Mozilla/5.0\"}\n","stream":"stdout","time":"2024-01-17T01:08:47.100782281Z"}
1211```
1217Interesting.
1219I am seeing that that Bun is having trouble parsing a URL that got passed to the request.
1221```
1222"10 | export async function mainFetchHandler(req: Request, server: Server) {\n"
1223"11 | const requestUrl = new URL(req.url);\n"
1224" ^\n"
1225"TypeError: \"stager64\" cannot be parsed as a URL.\n"
1226" at /apps/helloworld/main.ts:11:22\n"
1227" at mainFetchHandler (/apps/helloworld/main.ts:10:40)\n"
1229```
1231I don't know how it was able to receive this.
1233It was easy to see logs from the container that were not published by the formatted logger.
1244I was looking for a simple way to use JSX without using React.
1246I have been playing around with [Hono](https://hono.dev/) kind of a lot recently.
1248But I didn't really want to use it to describe my routes here.
1250At the moment, I like experimenting with raw Bun.
1252But it does have a really nice and simple JSX implementation.
1254In the docs, it doesn't really articulate how to use JSX outside of the response context.
1256So I took a look at its source code.
1260```
1261 html: HTMLRespond = (
1262 html: string | Promise<string>,
1263 arg?: StatusCode | ResponseInit,
1264 headers?: HeaderRecord
1265 ): Response | Promise<Response> => {
1266 this.#preparedHeaders ??= {}
1267 this.#preparedHeaders['content-type'] = 'text/html; charset=UTF-8'
1269 if (typeof html === 'object') {
1270 if (!(html instanceof Promise)) {
1271 html = (html as string).toString() // HtmlEscapedString object to string
1272 }
1273 if ((html as string | Promise<string>) instanceof Promise) {
1274 return (html as unknown as Promise<string>)
1275 .then((html) => resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}))
1276 .then((html) => {
1277 return typeof arg === 'number'
1278 ? this.newResponse(html, arg, headers)
1279 : this.newResponse(html, arg)
1280 })
1281 }
1282 }
1283```
1287```
1288import type { FC } from "hono/jsx";
1289const Bold: FC = ({ children }) => {
1290 return <span class="bold">{children}</span>;
1291};
1292console.log((<Bold>a bold string</Bold>).toString());
1293```
1311TODO: now that chrome supports these scrollbar colors, is should update the css
1315I have to put this here because i need to get around a paywall.
1319wow.
1321i tried using Hono with MDX.
1323it was so incredibly easy.
1325I thought for sure I was going to run into an absolute nightmare of trying to point all the JSX mappings to it, but it just worked with esbuild's mdx loader.
1327_including_ loading a base file of components for the built-ins.
1329I create an `mdxloader.ts` file
1331```
1333import { plugin } from "bun";
1334import mdx from "@mdx-js/esbuild";
1336plugin(
1337 mdx({
1338 jsxImportSource: "hono/jsx",
1339 providerImportSource: "./components/index.tsx",
1340 }) as any
1341);
1343```
1381hi. it's been a while.
1383i started thinking about building something again. but i really should probably
1384just use the thing i built.
1386So I guess I should write an entry.
1388I let the certs lapse on this site because, as stated at the top, I knew this was a little holiday hobby project that wasn't going to last.
1390And usually I do such a poor job of documenting those that there was no way I presumed I was going to be able to get it back in place.
1392But this project is literally self documenting.
1394So instead of trying to read the docs, I asked ChatGPT to do it.
1396It said that it couldn't read the website. I presumed this was due to certs.
1398So instead I had to try and think for a moment.
14001. Where the hell does the app actually run?
14012. If I stop it, will I remember how to restart it?
14023. Will I remember how to regenerate certs?
1404Ok so first instinct was to run a `ps` and see what was running. Not a lot
1406```
1407ps
1408 PID TTY TIME CMD
14093146258 pts/1 00:00:00 zsh
14103146845 pts/1 00:00:00 ps
1411```
1415```
1416docker ps
1417CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
141887bd9c9b44cc apps-helloworld "/usr/local/bin/dockβ¦" 7 months ago Up 12 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp apps-helloworld-1
1419```
1427That one is commited to memory. Kill all the running Docker images.
1429Congrats. I killed the website.
1431Second. Refresh the certs.
1433Thankfully even though ChatGPT couldn't read my website, it still spit out the most common command to refresh certs.
1439Boom, done. Now I just need to restart that Docker image...
1441Where did I do that?
1443Where are the apps on this machine?
1445`ls /` `ls ~` `su apollo && ls ~`
1447Nothing.
1449Uh oh. Did I do something stupid? Where the hell is it?
1451I usually prefer to keep apps in directory in `$HOME/{github_domain}/{gh_user}/{gh_project}. Never any guess work with being standard.
1453But nothing was around.
1455I finally moved to `/mnt` and remembered that I keep the apps in attached storage so that if the Droplet needs to get nuked, I have everything.
1457Well there it.
1459A simple `docker compose up` in the apps dir and I'm back.
1461I decided I should ask ChatGPT if it can read my website again now that the certs are healthy.
1463Some logs come through. They tried.
1465> I couldn't access the website due to a restriction in place on my browsing tool. Some websites may block automated tools from fetching their pages, or they might have a robots.txt file that prevents bots from accessing certain content. (From π€)
1467No hits to `robots.txt` though. You liar.
1469π The Wager: A Tale of Shipwreck, Mutiny and Murder
1470This book is very good. Compelling to read.
1472David Grann does an excellent job of characterizing these real people though their selection of quotations and contextualizing.
1474Grann described the logs that the ships would take. Reminding me to keep logging here.
1476Thinking about how those kinds of logs too have been automated in technology.
1478Just read raw machine logs to figure out what happened. Grann's book could never be written with just
1480```
1481{"msg":"ship's mast was broken", "timetamp": -7205122153}
1482{"msg":"ship's mast was repaired", "timetamp": -7204949353}
1483```
1485Though some moments could be enriched with this level of quantitative data.
1487But the logs that he drew from were created by people. They included the sentiment of the crew and synthesized the raw data with the human experience at the time of recording.
1489We should all do more writing.
1491It is crazy that the two books that I have mentioned on this log so far both include members of the Byron Family.
1493John Byron (the main subject) was the grandfather of the poet Lord Byron, the father of Ada Lovelace.
1495So even though I generated new certs with certbot, I failed to actually use them.
1497based on my docker compose file
1499```
1500version: "3"
1502services:
1503 helloworld:
1504 build:
1505 context: ./helloworld
1506 dockerfile: Dockerfile
1507 ports:
1508 - "80:80"
1509 - "443:443"
1510 volumes:
1511 - ./notes:/mdlogdir
1512 - /etc/letsencrypt/archive/:/hostcerts
1513 environment:
1514 - NODE_ENV=production
1515 - FDQN=zapplebee.online
1516 - CERTS_DIR=/hostcerts
1517 - NOTES_DIR=/mdlogdir
1518 restart: always
1520```
1522I am loading certs from the archive directory. I seem to remember chosing this was due to some file permission conflicts with mounting the files in docker.
1524anyway. inside of the archive directory the certs are created with an increment.
1537i've been struggling with the ssl certificate management for this site for a while now.
1539every time certificates expire, i have to ssh into the server, run certbot, and then remember to change the code that loads the certificates.
1541so i've rearchitected the whole setup. here's what changed:
15431. the bun app no longer handles https directly
15442. added caddy as a reverse proxy in front of the bun app
15453. caddy automatically handles all the certificate stuff
15464. the bun app now runs on port 3000, and caddy forwards to it
1548caddy automatically:
1550- gets certificates from let's encrypt
1551- configures https
1552- handles renewals
1553- redirects http to https
1555i've also simplified the bun app code by removing all the certificate handling stuff.
1557now i don't have to worry about certificate renewals at all. caddy handles it automatically in the background, and there's no code to update.
1559it also comes with some nice bonuses:
1561- http/2 support
1562- automatic compression
1563- better logging
1564- more secure tls defaults
1566the way i've set it up with docker volumes for the caddy data means that even if i restart the containers, the certificates persist. and if i ever need to upgrade caddy, i can just update the image version and restart.
1568it's a much more maintainable solution. no more expired certs.
Draft stub β replace these prompts with a real example.
The task
What were you trying to get done?
The collaboration
What did you ask the model to do? What did you keep, change, or verify yourself?
What feels different now
How does this compare with the hands-on debugging in the archive above?
Draft stub β a place to capture one recent debugging session.
The symptom
What went wrong, and how did you first notice?
The process
Where did AI help? Which parts still needed your judgment or direct investigation?
The outcome
What did you learn, and what would you do differently next time?