|
| 1 | +--- |
| 2 | +title: "jsonp - Who Asked?" |
| 3 | +written_on: "2024.11.23" |
| 4 | +public: true |
| 5 | +--- |
| 6 | + |
| 7 | +Often I need to prettify JSON. |
| 8 | +I probably don't need to justify that need to you. |
| 9 | +For many years I have used the site [jsonprettify.com](https://jsonprettify.com), which does the job well. |
| 10 | +It doesn't look quite how I would have it look, but it's fit for purpose and allows formatting at different levels of expansion. |
| 11 | + |
| 12 | +Recently, I (mistakenly) thought it had gone down. |
| 13 | +This was most likely due to me misremembering the URL on a new machine that didn't remember it for me, but I'm in too deep now to back out anyways. |
| 14 | + |
| 15 | +Finding my favorite tool missing, there's only one real solution. |
| 16 | +Build it myself. |
| 17 | + |
| 18 | +## Down the hole |
| 19 | + |
| 20 | +The construction started off pretty simple. |
| 21 | +I have been using Rust for the web for the last couple years, and though it changes frequently, I have found that temporarily forsaking JS has made it impossible to pick up again, so here we are. |
| 22 | +Leptos has been my tool of choice, and since I'm a Nix stan, I package it with Nix. |
| 23 | +All this I have been able to borrow from previous projects of mine. |
| 24 | + |
| 25 | +The main functionality wasn't so difficult either. |
| 26 | +The only hurdle is trying not to perform too many copies and not to skip frames when dealing with large payloads. |
| 27 | +I found that the HTML `<textarea>` tag produces far more latency than my code when receiving a large payload anyways (about 12 frames at 60fps compared to my 3-4 frames), so I'm not too concerned about it. |
| 28 | + |
| 29 | +`v0.1` was all well and good until I decided to deploy it. |
| 30 | +My tradition has been to build it into an OCI image using Nix and then ship it off to [Fly.io](https://fly.io) in a GitHub action, but this time I hesitated. |
| 31 | +I have been wanting to move to [CloudFlare Workers](https://workers.cloudflare.com/) as my primary Leptos deployment strategy, since it's free until 100,000 requests per month, and it fits most of my apps. |
| 32 | + |
| 33 | +## Wrangling `wrangler` |
| 34 | +`wrangler` is a pain in my ass. |
| 35 | +It's the CF workers et al. deployment tool, and it's a JS app. |
| 36 | +It doesn't seem like there's a community effort to circumvent it at all. |
| 37 | +It itself is fine, but it's packaged poorly within Nix. |
| 38 | +On `aarch64-linux` (hello to my Asahi brothers), it doesn't build, complaining something about MUSL `libc.so.1` being missing. |
| 39 | + |
| 40 | +After 15 wasted hours, I dropped it for a week. |
| 41 | +After a week, 10 minutes and 2 line additions fixed the problem. |
| 42 | + |
| 43 | +I need to do more research on the `wrangler` build process so that I can squish it down into the Nix ecosystem and forget about it, but I'm satisfied for now. |
| 44 | +I need to let my executive energy regenerate before I return to this problem again. |
| 45 | + |
| 46 | +## It works! |
| 47 | +This project -- dubbed `jsonp` but unrelated to the weird pre-CORS JS technique [JSONP](https://en.wikipedia.org/wiki/JSONP) -- is now live at [`https://jsonp.org/`](https://jsonp.org/). |
| 48 | +Feel free to use it, and direct your feedback to the [GitHub issues page](https://github.com/johnbchron/jsonp/issues). |
| 49 | +You can see the planned features there. |
| 50 | + |
| 51 | +Thanks for reading! |
0 commit comments