http_deno.mjs provides essential tools for HTTP servers running in Deno.
- Tools for serving files (with content type detection) and directories (with optional file filtering / whitelisting / blacklisting).
- Tools for simple HTML file servers, with automatic matching of "clean" URL paths such as
/
and/posts
to HTML files such asindex.html
andposts.html
.
Also see http
for routing and cookies, and live_deno
for live-reload tools for development.
Simple example of a server that serves files from the current directory, automatically matching URL paths to HTML files:
import * as hd from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected]/http_deno.mjs'
const srv = new class Srv extends hd.Srv {
// Serves files from the current folder, with no filtering.
dirs = hd.Dirs.of(hd.dirRel(`.`))
async res(req) {
const rou = new h.ReqRou(req)
return (
(await this.dirs.resolveSiteFileWithNotFound(req.url))?.res() ||
rou.notFound()
)
}
}()
await srv.listen({port: somePort})
The following APIs are exported but undocumented. Check http_deno.mjs.