DEV Community

Cover image for Deploying Next.js + Pocketbase to a single Fly.io machine
Nick
Nick

Posted on

Deploying Next.js + Pocketbase to a single Fly.io machine

I am constantly starting side projects, and like so many, I try to get the product out the door as quick as possible. I previously thought I have touched nirvana with Next.js + Supabase, but after so many projects you have to start paying Supabase the big bucks!

After two projects you need to pay Supabase 25 dollars a month, and each project you add is an additional 10 dollars a month. Pricey for side projects that are yet to make any money.

GitHub logo nicholasoxford / pocketwatcher

πŸš€ Production-ready Next.js template with PocketBase and shadcn/ui. Includes authentication, beautiful UI components, and one-command deployment.

PocketWatcher

Next.js PocketBase shadcn/ui Bun License

Overview

A modern full-stack template that combines the power of Next.js, the simplicity of PocketBase, and the beauty of shadcn/ui. Perfect for quickly bootstrapping production-ready web applications with authentication and a polished UI.

Features

  • πŸš€ Next.js 15+ App Router
  • πŸ“¦ PocketBase backend with built-in authentication
  • 🎨 Beautiful UI components from shadcn/ui
  • 🌐 Server-side rendering and client-side interactivity
  • πŸ”„ Form handling with React Server Actions
  • πŸ” Complete authentication system with email/password
  • 🐳 Production-ready Docker setup
  • ☁️ One-command deployment to Fly.io
  • πŸ”’ Secure cookie-based authentication
  • πŸ›‘οΈ Type-safe development with TypeScript
  • ⚑ Bun for fast package management and running scripts

Getting Started

Prerequisites

  • Bun runtime
  • Fly.io CLI (for deployment)

Local Development

  1. Clone the repository:
git clone https://github.com/yourusername/pocketwatcher.git
cd pocketwatcher
Enter fullscreen mode Exit fullscreen mode
  1. Install dependencies:
bun install
Enter fullscreen mode Exit fullscreen mode
  1. Start the development servers:

In one terminal, start PocketBase:

./pocketbase serve
Enter fullscreen mode Exit fullscreen mode

In another terminal, start the Next.js development server:

bun run dev
Enter fullscreen mode Exit fullscreen mode
  1. Access the applications

I was deploying so many Supabase projects I created a cli to self host Supabase on fly.io, Supafly

Side projects live and die by annoying blockers, the things that are getting in your way that shouldn't. After 10, 15, 20 or so side projects you might start to get a feel for what platform to reach for when.

What if we could host our entire app, in a familiar fashion, on one machine? Our database, API, and frontend. We should also be able to host this and have easy local development. Local development is classically a bit annoying with Supabase.

Charles Sheeler Painting

This gives you Authentication, a SQLite database (based), a self deploy next.js app, which is also your api layer, and the ability to do file upload + email easily.

Deploying Your Stack to fly.io

Getting your app live is surprisingly straightforward. Unlike traditional deployments where you're juggling multiple services, this is all handled in one go.
First-Time Setup

Install the Fly.io CLI if you haven't already

curl -L https://fly.io/install.sh | sh
fly auth login
Enter fullscreen mode Exit fullscreen mode

The Launch Process

bun run launch
Enter fullscreen mode Exit fullscreen mode

When you run this, you'll hit two prompts:

"Do you want to tweak these settings before proceeding?"
β†’ Just hit enter (the defaults work great)
"Would you like to allocate dedicated ipv4 and ipv6 addresses now?"
β†’ Type Y (you'll need this)
Enter fullscreen mode Exit fullscreen mode

Getting Your Admin Access

Here's the crucial part that often trips people up. Your PocketBase admin setup needs a special URL, but it's easy to find:

fly logs | grep pbinstal
This will show you something like:
Copyhttp://0.0.0.0:8090/api/admins/confirm-password-reset?token=YOUR_TOKEN_HERE

Enter fullscreen mode Exit fullscreen mode

"Important: Modifying the URL"
You'll need to change this URL before using it:

Replace http://0.0.0.0:8090 with https://your-app-name.fly.dev:8091
Keep the rest of the URL path and token exactly the same


Once you're set up, you can access your app at:

Main App: https://your-app-name.fly.dev
Admin Panel: https://your-app-name.fly.dev:8091/_/

Pro Tips

"Deployment Troubleshooting"

If you don't see the pbinstal log right away, wait a minute and try the logs command again
Keep that initial admin URL safe until you've set up your account
Once you've set up your admin account, that initial URL won't work anymore (this is a security feature)


Check out more of my writing at nicholasoxford.com

Project made with this: domainbobber.com

Top comments (0)