Simulating Apache mod_include for Vercel
For my Hugo static site hosted on Vercel, I wanted a simple way to include server-side logic, like a copyright notice, without setting up a full backend. I created a function that mimics Apache's mod_include
to inject dynamic content. It rewrites HTML requests through a handler that parses files for <!--#include ... -->
directives. The file
command injects file content, while the virtual
command fetches content from the /api
directory (like a modern /cgi-bin/
). Caching is crucial for performance. Check out the demo and code. A more robust solution like Cloudflare Workers' HTMLRewriter would be ideal, but this works for simple use cases.