wtw.dev/anything
A serverless API built with Astro and Vercel for searching all of my YouTube videos.
This project implements a serverless API that enables:
- YouTube video searching with cached results
- Direct video lookups by ID
- Automatic redirection to video URLs
/
├── public/
│ └── favicon.ico
├── src/
│ └── pages/
│ ├── index.astro
│ ├── videos.json.ts
│ └── [search].ts
├── package.json
└── vercel.json
- Clone the repository
- Install dependencies:
pnpm install
- Configure environment variables:
Create a
.env
file with:YOUTUBE_API_KEY=your_api_key YOUTUBE_PLAYLIST_ID=your_playlist_id
- Start the development server:
pnpm run dev
Redirects to YouTube video by exact ID (ex. wtw.dev/141), or falls back to a search query (ex. wtw.dev/react-hooks or wtw.dev/react+hooks). It'll redirect to the first search result that matches.
Returns a list of all video information as JSON.
- Fork or clone this repository
- Create a new project on Vercel
- Connect your repository
- Configure environment variables in Vercel:
YOUTUBE_API_KEY
YOUTUBE_PLAYLIST_ID
- Deploy!
The API implements two caching strategies:
- Search results: Cached for several days to balance freshness and performance
- Direct ID lookups: Permanently cached as video IDs are immutable
- Astro - Web framework
- Vercel - Serverless deployment platform
- YouTube Data API - Video data source
All commands are run from the root of the project:
Command | Action |
---|---|
pnpm install |
Install dependencies |
pnpm run dev |
Start local dev server at localhost:4321 |
pnpm run build |
Check types and build your production site to ./dist/ |
pnpm run preview |
Preview your build locally before deploying |