mirror of
https://github.com/rmdes/indiekit-endpoint-webmentions-proxy.git
synced 2026-02-25 05:56:20 +00:00
Webmentions proxy endpoint for Indiekit - proxies webmention.io API with server-side authentication
- JavaScript 100%
|
|
||
|---|---|---|
| lib | ||
| CLAUDE.md | ||
| index.js | ||
| package.json | ||
| README.md | ||
@rmdes/indiekit-endpoint-webmentions-proxy
Webmentions proxy endpoint for Indiekit. Proxies webmention.io API requests with server-side authentication, enabling real-time webmention fetching from frontend applications without exposing API tokens.
Why This Plugin Exists
The official @indiekit/endpoint-webmention-io plugin provides an admin dashboard view at /webmentions, but:
- No public API - Only provides protected routes (requires authentication)
- No database storage - Fetches directly from webmention.io on each request, doesn't cache in MongoDB
- Renders HTML - Returns server-rendered views, not JSON for frontend consumption
For a static site (like Eleventy) that needs real-time webmentions on the frontend via JavaScript fetch, the options were:
| Approach | Drawback |
|---|---|
| Expose token to frontend | Security risk - token visible in browser |
| Build-time data fetching | Not real-time, requires rebuild for updates |
| Fork official plugin | Maintenance burden of tracking upstream |
| Dedicated proxy plugin | Small additional dependency (this plugin) |
This plugin takes the dedicated proxy approach: a small, single-purpose endpoint (~70 lines) that keeps the token server-side while providing a public JSON API for frontends.
Installation
npm install @rmdes/indiekit-endpoint-webmentions-proxy
Configuration
// indiekit.config.js
export default {
plugins: [
"@rmdes/indiekit-endpoint-webmentions-proxy",
],
"@rmdes/indiekit-endpoint-webmentions-proxy": {
mountPath: "/webmentions-api", // API mount path (default)
token: process.env.WEBMENTION_IO_TOKEN, // Your webmention.io token
domain: "example.com", // Domain to fetch webmentions for
cacheTtl: 60, // Cache TTL in seconds (default: 60)
},
};
API Endpoints
GET /webmentions-api/api/mentions
Fetch webmentions from webmention.io.
Query Parameters:
page- Page number (default: 0)per-page- Items per page (default: 50)target- Filter by specific URL (optional)wm-property- Filter by webmention type:in-reply-to,like-of,repost-of,mention-of(optional)
Response: JF2 format webmentions from webmention.io
Example:
// Fetch all webmentions for page 0
fetch('/webmentions-api/api/mentions?page=0&per-page=50')
// Fetch only likes for a specific post
fetch('/webmentions-api/api/mentions?target=https://example.com/post&wm-property=like-of')
License
MIT