A Hono-based API with modular routes.
/
├── index.tsx # Main entry point for the API
├── routes/ # Directory for API route modules
│ └── favicon.ts # Favicon extraction endpoint
├── frontend/ # Frontend files
│ └── index.html # HTML test form
├── utils/ # Utility functions
│ └── getDomain.tsx # Function to extract domain from URL
└── README.md # This documentation file
Serves an HTML form for testing the favicon extraction functionality.
Returns information about the API endpoints.
Example Response:
{ "message": "Favicon Extractor API", "status": "success", "timestamp": "2025-05-20T18:16:58.497Z", "endpoints": [ { "path": "/favicon", "method": "POST", "description": "Extract favicon from URL" }, { "path": "/favicon/notion", "method": "POST", "description": "Process Notion webhook and update page icon" }, { "path": "/embed", "method": "POST", "description": "Add URL embed to a Notion page" } ] }
Extracts a favicon from a provided URL.
Request Body:
{ "url": "https://example.com" }
Success Response:
{ "success": true, "faviconUrl": "https://example.com/favicon.ico", "contentType": "image/x-icon", "faviconBase64": "base64-encoded-favicon-data" }
Error Response:
{ "success": false, "message": "Could not find favicon for the provided URL" }
Handles Notion webhooks to extract a favicon from a URL and update the corresponding Notion page with the favicon.
Request Body (from Notion webhook):
{ "pageId": "notion-page-id", "url": "https://example.com" }
Success Response:
{ "success": true, "message": "Favicon found and Notion page updated", "pageId": "notion-page-id", "url": "https://example.com", "faviconUrl": "https://example.com/favicon.ico" }
Error Response:
{ "success": false, "error": "Failed to update Notion page", "details": { /* error details */ } }
Adds an embed block with the provided URL to a Notion page.
Request Body:
{ "pageId": "notion-page-id", "url": "https://example.com" }
Success Response:
{ "success": true, "message": "Embed added successfully", "pageId": "notion-page-id", "url": "https://example.com", "response": { /* Notion API response */ } }
Error Response:
{ "success": false, "message": "Failed to add embed", "error": "Error message" }
Note: This endpoint requires a
NOTION_API_KEY
environment variable to be set with a valid Notion API key.
The API is built using Hono, a lightweight web framework. Each route is modularized in its own file for better organization and maintainability.
The favicon endpoint attempts multiple strategies to extract a favicon:
- First tries the standard
/favicon.ico
path - If that fails, it parses the HTML to find favicon link tags
- Returns the favicon URL and, for direct API calls, the base64-encoded favicon data
The /favicon/notion
endpoint integrates with the Notion API to:
- Receive webhooks from Notion containing a page ID and URL
- Extract the favicon from the provided URL
- Update the Notion page with the favicon URL as the page icon
This integration requires a Notion API key to be set as an environment variable (NOTION_API_KEY
). You'll need to create an integration in the Notion workspace and grant it access to the relevant pages or databases.
To add a new route:
- Create a new file in the
/routes
directory - Export a Hono router with your endpoint handlers
- Import and mount the router in
index.tsx
Example:
// In /routes/newEndpoint.ts
import { Hono } from "https://esm.sh/hono@3.11.7";
const router = new Hono();
router.get("/", (c) => {
return c.json({ message: "New endpoint" });
});
export default router;
// In index.tsx
import newEndpointRouter from "./routes/newEndpoint.ts";
// Mount the new router
app.route("/new-endpoint", newEndpointRouter);