DEPLOYED ON: https://serverless-blog-seven.vercel.app/
Welcome to the Serverless Blog Project! This repository contains the source code and configuration for a highly scalable, serverless blog platform. The project uses modern technologies like Hono, Cloudflare Workers, Prisma Accelerate, and a custom package for shared types and schemas. The application is designed to be efficient, maintainable, and developer-friendly.
- Serverless Architecture: Powered by Cloudflare Workers for high availability and low latency.
- Fast Development: Uses Hono for a minimal and efficient backend framework.
- Database Acceleration: Prisma Accelerate optimizes database queries for performance.
- Type Safety: Shared Zod schemas and types ensure consistent validation and type safety across backend and frontend.
- Custom Package: A reusable package
@utkarsh125/blog-common
contains shared logic and types.
- Hono: A lightweight web framework for serverless environments.
- Cloudflare Workers: Serverless compute platform for globally distributed applications.
- Prisma Accelerate: Enhances Prisma ORM for optimal performance in serverless environments.
- Zod: For runtime validation and TypeScript schemas.
- Custom Package: Shared between backend and frontend via npm.
- Node.js v16+
- npm or Yarn
- Cloudflare account (for Workers setup)
- Postgres database (local or remote)
-
Clone the repository:
git clone https://github.com/your-username/serverless-blog.git cd serverless-blog
-
Install dependencies:
npm install
-
Configure environment variables: Create a
.env
file at the root with the following:DATABASE_URL="your-postgres-database-url"
-
Initialize Prisma:
npx prisma db push
-
Install and build the shared package:
cd common npm install npm run build cd ..
-
Deploy Cloudflare Workers:
npm run deploy
medium-serverless/
├── common/ # Shared package (@utkarsh125/blog-common)
│ ├── schemas/ # Zod schemas for validation
│ ├── types/ # Shared TypeScript types
│ ├── package.json # Package configuration
│ └── index.ts # Package entry point
├── prisma/ # Prisma schema and migrations
│ └── schema.prisma # Database schema definition
├── src/ # Source code for Cloudflare Workers
│ ├── routes/ # API routes
│ ├── middlewares/ # Hono middlewares
│ └── index.ts # Entry point for the serverless application
├── package.json # Root package configuration
├── .env # Environment variables
└── README.md # Documentation
├── backend/...
├── frontend/...
- Start the development server:
npm run dev
- Access the application at
http://localhost:8787
.
Use the following command to deploy to Cloudflare Workers:
npm run deploy
Endpoint | Method | Description |
---|---|---|
/blogs |
GET | Fetch all blog posts |
/blog/:id |
GET | Fetch a single blog post |
/publish |
POST | Create a new blog post |
/blog/:id |
PUT | Update an existing post |
/blog/:id |
DELETE | Delete a blog post |
Feel free to reach out! utkarshpandey@gmail.com