A version of shadcn's taxonomy starter application optimized to run in the Edge Runtime.
Warning This app is an experimental application, primarily meant as a starting point, and may have bugs. This is a fork of taxonomy, and has diverged.
To deploy a pre-built, state-of-the-art Next.js application on Cloudflare Pages, which requires the edge runtime, though this repo can be deployed where edge runtime is supported.
Edge applications are often deployed more broadly, to "edge" servers close to users, and supports 0ms cold starts, unlike regular serverless applications. Because of this, performance may increase. Read more here.
Changes to the original taxonomy repo are struckthrough
- New
/app
dir - Routing, Layouts, Nested Layouts and Layout Groups
- Data Fetching, Caching and Mutation
- Loading UI
- Route handlers
- Metadata files
- Server and Client Components
- API Routes and Middlewares
- Authentication using
NextAuth.jsFirebase Auth withnext-firebase-auth-edge
-
- Why? The
next-auth
package is currently incompatible with the edge runtime.
- Why? The
-
next-firebase-auth-edge
allows easy use of cookies, to seamlessly power auth in server components, rather than send JWTs manually every request
- ORM using
PrismaDrizzle -
- Prisma is not currently compatible with edge runtime
- Database on
PlanetScale using the Serverless Driver -
- On April 8th, 2024, Planetscale's free tier is going away. DB has moved to Cloudflare D1!
- UI Components built using Radix UI
- Documentation and blog using MDX
and Contentlayerandnext/mdx
-
- Contentlayer seems to generate code that is evaluated during runtime. This evaluation uses edge runtime-incompatible APIs.
- Subscriptions using Stripe, adapted to work in edge runtime
- Styled using Tailwind CSS
- Validations using Zod
- Written in TypeScript
Compared to the taxonomy repo repo, the following has changed:
- All routes, including server-rendered pages, include
export const runtime = "edge";
to opt into edge runtime. - Auth has moved to Firebase Auth, using
next-firebase-auth-edge
since NextAuth is incompatible with edge runtime. - Prisma has been replaced with Drizzle, which is edge runtime-compatible.
- Stripe has been modified to use Web Crypto,
constructEventAsync
, andcreateFetchHttpClient
to add edge compatibility. - Contentlayer has been replaced with
next/mdx
and manually routed pages since next-contentlayer uses incompatible APIs. - Usage of
next/image
has been replaced since it's currently unsupported by Cloudflare Pages. - Use of
vercel/og
is disabled since it's currently broken in Next.js on Cloudflare Pages. - Use of
EditorJS
is disabled since it seems to import wasm, causing next-on-pages builds to fail. See this issue for more details. - Yarn: shadcn/ui, the component library for this project, is in a separate package named
components
, while the Next.js app is in another. This repo uses yarn workspaces to link them. - Planetscale database has been replaced with Cloudflare D1. You can launch taxonomy-edge with a database of your choice by replacing usages of D1 with your database.
- Install dependencies using pnpm:
yarn
- Copy
.env.example
to.env.local
and add your own variables.
cp packages/web/.env.example packages/web/.env.local
- Start the development server:
yarn run web
- Push this into a Github repo.
- Follow Cloudflare's instructions here
- Once on the "Set up builds and deployments" step, for configuration options, set:
Build command
toyarn && cd packages/web && npx @cloudflare/next-on-pages
Build output directory
to/packages/web/.vercel/output/static
- Complete the Cloudflare instructions set above
- Make sure you set all environment variables, or your build will fail!
- Don't forget the
NODE_VERSION
env var that the instructions above mention! Node 18.19.1 is the minimum supported Node version. - Note: your
FIREBASE_PRIVATE_KEY
env var must be stripped of all\n
. Cloudflare environment variables do not seem to escape/unescape these properly, at least when entered from the dashboard.
- Don't forget the
In the ./packages/web
directory, you can:
- run
yarn run db:migrate-gen
to create a migration based on the state of your./db/schema.ts
file - run
yarn run db:migrate-list
to list any unapplied migration files. Options:--local
for local DB,--preview
for preview environment DB, and no flag for main/production DB. - run
yarn run db:migrate-prod
to apply any migrations against your remote, production database -
- run
yarn run db:migrate-local
to apply migrations against your local db
- run
-
- run
yarn run db:migrate-preview
to apply migrations against your remote, preview db (as defined by preview_database_id inwrangler.toml
)
- run
All operations are run against the database named taxonomy-edge
locally to start.
- Table of contents in certain MDX pages is disabled for now
Licensed under the MIT license.