I’ve found a use case for Workers within my current pre-sales role to demonstrate our integration capabilities. We’ve developed an API but there are currently no demos, SDKs, or other formal integrations built so, for the purpose of demonstrating the API, I’ve built a demo web app hosted on Cloudflare Workers.
Starting at the data end
First off - I wanted something up and running super quick as a proof of concept. We’ve recently launched the new UniFi OS Server so this is a good start. At my home I’ve got a 2011 Mac mini running duties as a little server running Ubuntu. I deployed UniFi OS Server 4.2.23 onto this and got it setup. By default it serves its web UI (and its API) on port 11443.
It was a simple enough test once setup to check the service was up and running. First, a quick browse to the internal IP address on port 11443 - success. This gave me a chance to setup the server with my UI Account and also cut an API key within the Settings. Then I ran a simple test for API using the key and setting the base URL to include port 11443 and the GET /v1/info endpoint to determine this was also operational. Success again ✅.
Connecting in a secure way
Now, I want to access this server remotely so my Worker can hit the API. That could be done a couple of ways:
- Setup a certificate on the server, a dynamic DNS entry, and port forward on my home gateway
- Use a Cloudflare tunnel to do all the hardwork for me
Given I was already in Cloudflare-land, I opted for the second. This was a super simple addition. Setup cloudflared on my personal server and then set a subdomain of my heath.works to for HTTPS traffic to localhost:11443 (seeing as the OS Server was hosted on the same appliance). A few clicks and unifi.heath.works was online.
One more step was then reverting to Postman and running the same test before to hit GET /v1/info but this time using the URL formed from the subdomain. Tested and this works! That means my Worker will be able to reach my UniFi OS Server.
Building a Worker and initial proof of integration
I had a few Workers setup from my first foray into Cloudflare Workers - I decided to nuke them and start afresh to see what I could recall/understand and leveraged a lot of ChatGPT’s new Study Mode to get my understanding built progressively.
All I have right now is a simple one-pager site index.html which has a button to check that it can call the API. The client-side JS is a simple script that calls a separate path /api/version which returns the JSON response and dumps it on the page to show that it’s working. That’s all for now.
Where am I taking this next?
Some simple ideas:
- a demo of commonly used integrations for UniFi Network
- Captive Portal
- Hostpot Vouchers
- when UniFi Protect comes to UniFi OS Server
- a demo of capturing static images from camera and serving these in the UI
- some way of showing webhook events raised by the Protect system which will likely involve a webhook receiver worker separately storing events to some persistent storage
- when UniFi Access comes to UniFi OS Server
- a web app in two parts - one that allows you to create a visitor/user; the other that gives a user experience and shows the ability to unlock a door
- a simple one-page Access status page (which doors are open/close and their last open time)
A review on my progress
I like to learn recursively. I will do something, do it again, break it, understand why it works, fix it, break it fixing it, then work out the mechanics of every bit before I move on. Using ChatGPT helps me with this because I can ask it slow down and explain every detail to me, and ask the same stupid questions again and again without it losing patience. It’s pretty great for that. It’s also great for getting stuff wrong and forcing me to explore why ChatGPT itself is wrong and therefore using other (better?) reference material to learn.
My last post was a while ago. It’s been a busy year getting stuck in to life at Ubiquiti - understanding Cloudflare Workers and building a simple web app has been on the agenda all along.
I set some goals in that post - here’s a review:
- take more of a step into the technical
- on the road to this
- not shit the bed doing it (read: work on self-compassion)
- more self pace and allowance for the way I work is in play
- use a familiar set of tools combined with some I don’t know
- happy to tick this off now combining systems and patterns I know with those that are more unfamiliar
- put it out there and leave it be
- yep - go see demo.heath.works
- set an example to my kids that learning happens all life long
- this goes with the self-compassion point…
These will be perpetual goals really, but nice to see that I’m doing what I set out a year ago.
A bit of introversion this year has done me a ton of favour. I’ve learnt more about my style, what challenges me, and how to find focus and compassion. A lot of the above came from taking a deep breath, and just iterating again and again until I’ve understood a concept in depth even if I’ve only moved the needle a tiny bit.
I can be distractable. In the past I’ve criticised myself for this. In the past I’ve tried to police this. It turns out that was wrong. I now allow that distraction but I give it a context. That gives me a lot of benefits (horizontal learning) but without losing control of my objective (scope creep; going down the rabbit hole).
I’ve found a way of developing my focus further has come in the form of long-distance running. It turns out having hours out on the road at a time with nothing but yourself to focus on is a great way to learn about yourself and rid yourself of immediacy that fuels distraction. A lot of my knowledge has developed from me taking this time with myself.