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
/appdir - 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-authpackage is currently incompatible with the edge runtime.
- Why? The
-
next-firebase-auth-edgeallows 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-edgesince 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, andcreateFetchHttpClientto add edge compatibility. - Contentlayer has been replaced with
next/mdxand manually routed pages since next-contentlayer uses incompatible APIs. - Usage of
next/imagehas been replaced since it's currently unsupported by Cloudflare Pages. - Use of
vercel/ogis disabled since it's currently broken in Next.js on Cloudflare Pages. - Use of
EditorJSis 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.exampleto.env.localand 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 commandtoyarn && cd packages/web && npx @cloudflare/next-on-pagesBuild output directoryto/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_VERSIONenv var that the instructions above mention! Node 18.19.1 is the minimum supported Node version. - Note: your
FIREBASE_PRIVATE_KEYenv 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-gento create a migration based on the state of your./db/schema.tsfile - run
yarn run db:migrate-listto list any unapplied migration files. Options:--localfor local DB,--previewfor preview environment DB, and no flag for main/production DB. - run
yarn run db:migrate-prodto apply any migrations against your remote, production database -
- run
yarn run db:migrate-localto apply migrations against your local db
- run
-
- run
yarn run db:migrate-previewto 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.