This api uses Cloudflare-worker, Hono, Cloudflare-D1 database(sqlite), typescript and drizzle-orm to do CRUD operations for web-archive web-app.
Clone the repo:
git clone [email protected]:nabeelcodes/web-archive-hono-api.git
cd web-archive-hono-api
Install the dependencies:
pnpm install
Set the environment variables:
cp .dev.vars.example .dev.vars
# open .dev.vars and modify the environment variables
Running in development:
pnpm run dev
Running in production:
# deploy to cloudflare
pnpm run deploy
The environment variables can be found and modified in the .env
file.
# number of articles in a page
POSTS_PER_PAGE=
# JWT secret
JWT_SECRET=
# new user sign up secret
ADMIN_SECRET=
# URL frontend (localhost for development)
FRONTEND_URL=
# cors whitelist urls
CORS_WHITELIST=
api
|--src/index.ts # App entry point
|--src/db/schema # database schema
|--src/middleware/ # custom middlewares
|--src/controllers/ # controllers(functions)
|--src/utils/ # Utility classes and functions
List of available routes:
User routes:
`POST api/users/register` - Create a user
`POST api/users/login` - Login user
`GET api/users/current` - Get current user(private route)
Post routes:
`GET api/posts` - Fetch all posts
`GET api/posts/:id` - Fetch single post
`POST api/posts` - Create new post(private route)
`PUT api/posts/:id` - Update a post(private route)
`DELETE api/posts/:id` - Delete a post(private route)
Tag routes:
`GET api/tags` - Fetch all tags