Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 1.95 KB

http_deno_readme.md

File metadata and controls

60 lines (44 loc) · 1.95 KB

Overview

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 as index.html and posts.html.

Also see http for routing and cookies, and live_deno for live-reload tools for development.

TOC

Usage

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})

API

Undocumented

The following APIs are exported but undocumented. Check http_deno.mjs.