I go walking in your landscape.
cesalt
|
August 28th 2023
close up of three topo chico mineral waters

This is an image of three bottles of Topo Chico that I took.

I love Topo Chico.

The bubbles are like tiny naval mines.

If it was all I could drink forever, I'd be alright.

In my last post I spoke about self hosting a PocketBase backend for THIMB.

Now I'm hosting a PocketBase backend for the site on an old macbook.

PocketBase is a super tiny open source backend solution.

It's built on top of SQLite and has a ton of features out of the box.

I used ngrok to expose the port on that old macbook to the web.

Why did I do this?

I'm so bored.

Should you care?

Yes.

How did I do it?

Here's an explanation in 5 parts.

Part 1 - Selecting Your PocketBase Flavor
picking a pocketbase version for your processor

Everything in life is about making decisions.

You need to be informed -- or believe that you are -- to make the correct decision.

In my case, the correct choice was to download the version of PocketBase designed to run on Intel based macs.

Also in my case, the correct choice was to ignore the warning that tells you PocketBase isn't ready for production critical applications.

After downloading the zip file and being confused about why Chrome is flagging your download as irregular, unzip the thing.

Open your terminal, cd into the PocketBase directory, and run ./pocketbase serve

Hot Take Alert!

I prefer the stock terminal on OSX. Hell, sometimes I even use the one in VS Code. It is convenient.

Don't worry, I'll add comments to the site in my next post just so y'all can call me dumb and tell me that iTerm is superior.

Part 2 - PocketBase: They've done everything for you!

Once your instance of PocketBase is up and running you'll get a sweet little propmt in your terminal.

Navigate to http://127.0.0.1:8090/_/ to access the Admin UI.

Enter the credentials you want for your admin account.

Don't forget it because PocketBase can only handle 10,000+ persistent real time connections.

And for some reason you need users.

And your blog is definitely going to blow up.

And you'll eventually have to switch to a real backend.

And boom! Just like that you've got a backend! And they said web dev was hard...

PocketBase uses collections. Collections are tables. You get a user collection by default.

pocket base admin dashboard
Part 3 - People as Users

But there's a problem.

This site uses Astro.

Astro ships zero JavaScript by default.

But you want to use the PocketBase SDK for registration and user authentication and you need JavaScript to do that.

Luckily for you, a bunch of smart people at Astro have you covered.

We can still have blazingly fast page loads and the ability to say terrible things to each other that we never would say in real life!

It's as easy as passing the client:load attribute to your components in your .astro files!

Check out the Astro Docs for using framework components, Astro Islands, and selective hydration.

Now sign up if you feel like it. Maybe I'll email you when you can log in, lol. You can see the request in the Network tab in the dev tools.

And if the request fails, I probably shut my laptop. Yes, I know about amphetamine. And I need to figure out how I'm handling toast notifications. This is all just for fun. Chill, Winston.

Part 5 - ngrok

ngrok is pretty freaking rad.

They provide a service that allows you to expose local ports to the web really quickly and securely.

At my last job I used this all the time to test third party REST and GraphQL API integrations I built.

And now it is even better.

Previously whenever you'd spin up ngrok and serve your localhost you'd get a random domain, but now they are just giving away static ones.

It is incredibly easy to set up. And is going to have some fun use cases down the road.

Next steps: Sign up for ngrok, get a free static domain from them, authenticate your box, and serve 8090 to the world!

In Conclusion

This was fun.

I really like PocketBase and their UI. It's all so easy to get set up.

Next steps are to containerize it, host it on some free tier of some cloud provider, probably Fly.io.

And if anyone actually signs up, migrate any data over to the cloud.

Also, I need to build a comments section.

And probably a login portal.

Because unless you know your way around the command line, you can't log in.

Also there is nothing to do when you're logged in, lol.

And implement some form validation.



Thanks for swinging by 🫠

Recent Posts
Rosemary, Heaven restores you in life.
09/21/2023
When you couldn't see me.
09/18/2023
You really messed me up
09/14/2023
© cesalt 2023