A modern Cloudflare Workers API for generating beautiful, customizable SVG file icons on-the-fly โจ
Transform any file extension into a stunning visual icon with our dynamic SVG generation API. Built with Hono framework and deployed on Cloudflare's edge network for ultra-fast global performance. Perfect for file managers, documentation sites, developer tools, and any application that needs beautiful file type representations.
- Dynamic SVG Generation - Create file icons for any extension instantly
- Edge-First Performance - Deployed on Cloudflare Workers for global speed
- Modern Tech Stack - Built with Hono, Vite, and TypeScript
- Fully Customizable - Control colors, fonts, sizes, and styling
- Server-Side Rendering - Interactive documentation with React/JSX
- REST API - Simple HTTP endpoints for easy integration
- Beautiful UI - Interactive documentation and testing interface
- Zero Cold Starts - Cloudflare Workers ensure instant responses
- Open Source - ISC licensed and community-driven
See Icon Forge in action! Here are some examples of dynamically generated file icons:
Generated with: GET /file-icon?ext=js
Generated with: GET /file-icon?ext=exe
๐ก Try it yourself: Visit the live demo to generate icons in real-time!
- Node.js 18+ (for development)
- npm or yarn
- Cloudflare account (for deployment)
git clone https://github.com/egyjs/icon-forge.git
cd icon-forge
npm install
# Start development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Deploy to Cloudflare Workers
npm run deploy
Generate a file icon by simply making a GET request:
# Generate a JavaScript file icon
curl "https://icon-forge.el3zahaby.workers.dev/file-icon?ext=js"
# Generate a PDF icon with custom colors
curl "https://icon-forge.el3zahaby.workers.dev/file-icon?ext=pdf&textColor=%23ffffff&bgColor=%23e74c3c"
https://icon-forge.el3zahaby.workers.dev
http://localhost:5173
Generate a custom file icon SVG
Parameters:
ext
orextension
(required) - File extension (1-10 alphanumeric characters)textColor
(optional) - Hex color for text (e.g.,#ffffff
)fontSize
(optional) - Font size in pixels (10-40)bgColor
(optional) - Background color in hex (e.g.,#3498db
)
Example:
GET /file-icon?ext=png&textColor=#0078d4&fontSize=25&bgColor=#f44336
Health check endpoint
All successful requests return SVG content with appropriate headers:
- Content-Type:
image/svg+xml
- Cache-Control:
public, max-age=86400
<!-- JavaScript file -->
<img src="https://icon-forge.el3zahaby.workers.dev/file-icon?ext=js" alt="JS file">
<!-- Python file -->
<img src="https://icon-forge.el3zahaby.workers.dev/file-icon?ext=py" alt="Python file">
<!-- PDF document -->
<img src="https://icon-forge.el3zahaby.workers.dev/file-icon?ext=pdf" alt="PDF file">
<!-- Large TypeScript icon with custom colors -->
<img src="https://icon-forge.el3zahaby.workers.dev/file-icon?ext=ts&textColor=#ffffff&fontSize=25&bgColor=#3178c6" alt="TypeScript file">
<!-- Small JSON icon -->
<img src="https://icon-forge.el3zahaby.workers.dev/file-icon?ext=json&fontSize=20&bgColor=#ff9500" alt="JSON file">
<div class="file-list">
<div class="file-item">
<img src="/file-icon?ext=docx&bgColor=#2b579a" class="file-icon">
<span>document.docx</span>
</div>
</div>
const FileIcon = ({ extension, size = 32 }) => (
<img
src={`/file-icon?ext=${extension}&fontSize=${Math.min(size, 40)}`}
width={size}
height={size}
alt={`${extension} file`}
/>
);
<template>
<img
:src="`/file-icon?ext=${extension}&bgColor=${color}`"
class="file-icon"
:alt="`${extension} file`"
/>
</template>
- Node.js 18+ (for development tooling)
- npm or yarn
- Cloudflare account (for deployment)
-
Clone the repository
git clone https://github.com/egyjs/icon-forge.git cd icon-forge
-
Install dependencies
npm install
-
Start development server
npm run dev
-
Visit the application Open http://localhost:5173 in your browser
icon-forge/
โโโ src/
โ โโโ index.tsx # Main Hono application
โ โโโ renderer.tsx # JSX renderer setup
โ โโโ style.css # Application styles
โ โโโ components/
โ โโโ iconTemplate.tsx # SVG icon component
โ โโโ index.tsx # Homepage component
โโโ public/
โ โโโ favicon.ico # App favicon
โโโ package.json # Dependencies and scripts
โโโ tsconfig.json # TypeScript configuration
โโโ wrangler.jsonc # Cloudflare Workers config
โโโ vite.config.ts # Vite build configuration
โโโ README.md # This file
- Hono web framework setup
- SVG generation logic
- Request validation and routing
- CORS handling
- JSX server-side rendering
- Vite integration for development
- CSS and asset loading
- React component for SVG generation
- Dynamic styling and customization
- Professional design system
- Server-side rendered React interface
- Real-time icon preview
- Parameter validation and testing
npm run dev # Start development server with Vite
npm run build # Build for production
npm run preview # Preview production build locally
npm run deploy # Deploy to Cloudflare Workers
The project uses wrangler.jsonc
for Cloudflare Workers deployment:
- Compatibility date: 2025-06-02 (matches the latest Workers runtime)
- Main entry:
./src/index.tsx
- Build system: Vite with SSR components
- Development: Uses Vite dev server (http://localhost:5173)
- Production: Deployed to Cloudflare Workers edge network
- 8 predefined background colors for consistent theming
- Stable color assignment using string hashing
- Full hex color validation
- Fallback to defaults for invalid inputs
- Self-hosted Fredoka font (embedded in SVG)
- Automatic size adjustment for long extensions
- Consistent typography across all icons
- Edge-first deployment on Cloudflare Workers
- Zero cold starts with Workers runtime
- Client-side caching with max-age headers
- Efficient SVG generation with React components
- TypeScript for type safety
- Hono framework for lightweight performance
- Vite for fast development and optimized builds
- Server-side rendering for interactive documentation
Visit the development server at http://localhost:5173
to test different configurations interactively.
# Test basic functionality
curl -s "https://icon-forge.el3zahaby.workers.dev/file-icon?ext=test" | head -n 5
# Test error handling
curl -s "https://icon-forge.el3zahaby.workers.dev/file-icon" # Should return 400 error
# Test health endpoint
curl -s "https://icon-forge.el3zahaby.workers.dev/health"
# Test response time
time curl -s "https://icon-forge.el3zahaby.workers.dev/file-icon?ext=perf" > /dev/null
# Test deployment locally
npm run preview
# Deploy to Cloudflare Workers
npm run deploy
We love contributions! Whether it's bug fixes, feature additions, documentation improvements, or design enhancements, your help makes this project better for everyone.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Test your changes thoroughly
- Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- ๐จ Design: New SVG templates, icon styles, color schemes
- ๐ง Features: Additional customization options, new endpoints, Workers-specific optimizations
- ๐ Documentation: Tutorials, examples, API guides, Cloudflare Workers deployment guides
- ๐ Bug Fixes: Performance improvements, edge case handling, TypeScript type fixes
- ๐งช Testing: Unit tests, integration tests, Workers environment testing
- ๐ Internationalization: Multi-language support
- โก Performance: Edge computing optimizations, caching strategies
- ๐ Security: Input validation, rate limiting, security headers
- Follow existing TypeScript patterns and Hono conventions
- Test changes locally with
npm run dev
andnpm run preview
- Ensure compatibility with Cloudflare Workers runtime
- Update documentation for API changes
- Use meaningful commit messages following conventional commits
- Keep pull requests focused and atomic
- Test deployment with
npm run deploy
before submitting PRs
- Desktop file managers
- Cloud storage interfaces
- File sharing platforms
- Code editors and IDEs
- Documentation generators
- Build system outputs
- CMS file browsers
- Media libraries
- Document management systems
- Coding tutorials
- File type education
- Programming courses
Development server issues
# Kill any process using port 5173 (Vite default)
netstat -ano | findstr :5173
taskkill /PID <PID> /F
# Clear Vite cache
rm -rf node_modules/.vite
npm run dev
Build failures
# Clear build cache and reinstall
rm -rf node_modules dist
npm install
npm run build
Deployment issues
# Verify Wrangler authentication
npx wrangler whoami
# Check deployment logs
npx wrangler tail
# Test locally before deploying
npm run preview
Invalid SVG output
- Check browser developer tools for errors
- Verify SVG template component exists in
src/components/iconTemplate.tsx
- Validate input parameters match API specification
- Test with simple extensions first (e.g.,
ext=js
)
CORS errors
- CORS is handled automatically by Hono middleware
- Check request headers and methods
- Verify deployment configuration
TypeScript errors
# Check for type errors
npx tsc --noEmit
# Update type definitions
npm run cf-typegen
This project is licensed under the ISC License - see the LICENSE file for details.
- Fredoka Font - Beautiful typography by Google Fonts
- Hono - Ultra-fast web framework for Cloudflare Workers
- Vite - Next generation frontend tooling
- Cloudflare Workers - Edge computing platform
- SVG Community - Inspiration and best practices
- Open Source Contributors - Making this project better every day
- ๐ Support: el3zahaby@gmail.com
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ Live Demo: https://icon-forge.el3zahaby.workers.dev
- ๐ ๏ธ Development:
npm run dev
then visit http://localhost:5173
- Custom Font Support - Upload and use custom fonts
- Icon Templates - Multiple visual styles and layouts
- Batch Generation - Generate multiple icons at once
- Advanced Styling - Gradients, shadows, animations
- Analytics Dashboard - Usage statistics and insights
- Edge Caching - Enhanced performance with Cloudflare Cache API
- Plugin System - Extensible architecture for custom generators
- REST API v2 - Enhanced endpoints with more customization options
- WebAssembly Integration - Ultra-fast SVG processing
โญ Star this repository if you find it helpful!
Made with โค๏ธ by Egyjs
Live Demo โข Documentation โข Contributing โข License