It's been a minute since I gave VSCodium a break, but after upgrading GoToSocial to the latest I absolutely needed to get back to building out my /now page to finally fully automate publishing via shiny new JSON Feed from my GTS instance. As with all things simple it turned out to be much less straightforward than I hoped, but the journey was worth it.
Me reason for choosing JSON Feed over RSS was ultimately about browser compatibility, but I did thoroughly enjoy the process of playing with XSLT. So with JSON on-deck, I first needed to figure out how to get my hands on the feed. And while this seems simple enough, GTS chose to provide a single /feed.rss endpoint which defaulted to RSS but where one could select the type of feed by adding a header to the request {“Accept”: “application/feed+json”} rather than presenting a simple /feed.json endpoint. It will become clear why it was such a problem for me later, but for now suffice it to say that CORS and avoidable headers don’t mix well.
Before I get to the frustrating part, I should note that I strangely enjoyed the templating part of this journey. I found XSLT quite capable and satisfying to work with, despite loathing XML, so I was actually looking forward to templating the transformation from JSON to HTML. I started with Mustache and Handlebars both of which worked as promised and were super lightweight, but that featherweight distinction meant that some key features like contains-based filtering and basic substrings would require me to write some basic functions and register them as part of the template engine. I suspect it would have been faster for me to do exactly that, but I chose instead to work through my template with not 1 or 2 but three – thankfully similar – templating tools finally landing on Nunjucks. Beyond that there’s not much to say, Nunjucks is more capable than I need and I’m sure loading that .js file is unnecessarily tasing on the poor suckers who visit my page. But it was easy for me ;-)
Now given that I have learned nearly everything I know about cos-playing as a sys admin from messing around over the past year, I’m sure my own choices led to this — Currently my “stack” consists of a couple low-power Raspberry Pis connected to the world via Cloudflare Tunnels. It was quite the accomplishment for me when I finally moved my site off the now retired Pages feature at Codeberg an onto my own little NGINX server — but it turns out that somewhere in the mix of HTMX, NGINX, CF Tunnels, Docker, and GoToSocial my ability to add the requisite header to get the JSON version of the feed triggered CORS. Of course CORS is great when you expect it, but I hadn’t set up any Access-Control-Allow-Origin or Access-Control-Allow-Headers rules on my server, so it didn’t make sense.
No fear, I can google (note the little G in that verb) with the best of them and promptly had the access control headers in place. Problem solved not solved. No matter what I tried – I even phoned a friend (thanks @oli ) – I couldn’t figure it out. I eventually became convinced that Cloudflare was adding CORS restrictions on my behalf – thanks I think – but I couldn’t figure out how to allow the headers I was sending.
Then tonight, while limping through my taekwondo class with a strained hip flexor, I had an epiphany! If I can’t send the request header from the site without violating the cross-origin restrictions, I could just add the application/feed+json header via a Cloudflare transform rule for all requests to the /feed.rss endpoint!! I apologize to anyone who wants a proper XML based feed, but this is my site so you all get JSON. (Check out NetNewsWire for a fantastic open-source feed reader on Mac/iOS that supports JSON Feeds.) This little scheme allowed me to add the HTMX hx-request=‘{“noHeaders”: true} attribute, which would normally cause GTS to default to XML, and let the necessary yet guilty header be added in transit outside the prying eyes of whatever CORS gremlin was lurking in my stack.
The moral of the story is, don’t give up. With enough ignorance and uninformed decision making you too might learn a thing or two along the way like how to work around problems without actually solving them. If you’ve made it to the end of this and didn’t already notice the link to my /now page above you may want to check it out: HaugenHus: Now (Kaleb)
#Now #GoToSocial #JSONFeed #HTMX #NGINX #Fediverse #CORS #NotASysAdmin #SelfHost









