<< Previous | Next >>

Daily Learnings: Wed, Sep 11, 2024

Criticism is something you can easily avoid by saying nothing, doing nothing, and being nothing. — Aristotle

Fixing My Daily Quote Issues

In my previous daily learning entry from Sept 9 I pointed out in the little block that usually stores my daily quote that I was running into some DNSSEC issues when attempting to hit https:api.quotable.io. I outlined more about this in a linked Github issue, including screenshots of a tool that introspects the expired certificate. I finally fixed the issue for my local network today, and wanted to write about what led to me having this, and how I fixed it.

Why I was having this issue

My local network enforces DNSSEC issues more strictly than others because I run PiHole for local network ad blocking, security, and local DNS. I also run unbound for a local recursive DNS server.

I noticed that my daily quotes wouldn’t generate when using Obsidian only when I was on my home network. If I was out of my house, they worked just fine. After doing more investigation, I found the issue was a Bogus status that PiHole was giving for all requests to https://api.quotable.io. You can check the linked Github issue above for screenshots.

How I fixed it

The Proxy

I created a proxy using val.town, a super simple, lightweight deno service for creating small Javascript programs and putting them on the internet. You can run the proxy endpoint here:

https://johndturn-quotableapiproxy.web.val.run/

Shoutout to the Syntax podcast for intro-ing me to this free service like a year ago.

This small proxy hits the http://api.quotable.io/quotes/random endpoint (notice http, not https), and then sends the data back to the client.

The Custom Templater Script

I use the Templater plugin for all of my Obsidian templates. It allows for creating and calling custom Javascript functions. So I did the following:

// My personal proxy for the Quotable API, based on the following open issue:
// https://github.com/lukePeavey/quotable/issues/239
const apiUrl = "https://johndturn-quotableapiproxy.web.val.run/";

async function start() {
  let quote;
  let cite;
  const response = await fetch(apiUrl);
  const data = await response.json();

  if (response.ok && data.length > 0) {
    const quoteObj = data[0];
    quote = quoteObj.content;
    cite = quoteObj.author;
  } else {
    quote = "An error occurred";
    console.log(data);
  }

  return `> [!quote]
> ${quote}
> — <cite>${cite}</cite>
`;
}

module.exports = start;

The Updated Templates

I then updated all of my templates, removing all calls to tp.web.daily_quote(). Instead, I placed tp.user.randomQuote().

Final Thoughts

I know that I could have skipped the step of creating a val.town-based proxy, and instead simply created the user-defined script that calls to http://api.quotable.io directly, bypassing HTTPS. However, I’m happy I did all this for a couple of reasons:

References