diff --git a/deno.json b/deno.json index 1e59a05..0f7a6e9 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,7 @@ { "name": "@andyburke/serverus", - "version": "0.0.1", + "description": "A flexible HTTP server for mixed content. Throw static files, markdown, Typescript and (hopefully, eventually) more into a directory and serverus can serve it up a bit more like old-school CGI.", + "version": "0.0.2", "license": "MIT", "exports": { ".": "./serverus.ts", diff --git a/handlers/markdown.ts b/handlers/markdown.ts index e59e0eb..913e639 100644 --- a/handlers/markdown.ts +++ b/handlers/markdown.ts @@ -1,3 +1,8 @@ +/** + * Default handler for returning Markdown as either HTML or raw Markdown. + * @module + */ + import * as path from '@std/path'; /** diff --git a/handlers/static.ts b/handlers/static.ts index 192aa4c..2769ee2 100644 --- a/handlers/static.ts +++ b/handlers/static.ts @@ -1,3 +1,8 @@ +/** + * Handles requests for static files. + * @module + */ + import * as path from '@std/path'; import * as media_types from '@std/media-types'; diff --git a/handlers/typescript.ts b/handlers/typescript.ts index 9fe35cb..6726a77 100644 --- a/handlers/typescript.ts +++ b/handlers/typescript.ts @@ -1,15 +1,27 @@ +/** + * Handles requests for which there are Typescript files that match + * and adhere to the `ROUTE_HANDLER` interface. + * @module + */ + import { walk } from '@std/fs'; import { delay } from '@std/async/delay'; import * as path from '@std/path'; import { getCookies } from '@std/http/cookie'; +/** A `PRECHECK` must take a `Request` and `meta` data and return a `Response` IF THERE IS A PROBLEM. */ export type PRECHECK = ( request: Request, meta: Record ) => undefined | Response | Promise; + +/** A `PRECHECK_TABLE` maps from HTTP methods to your `PRECHECK`s. */ export type PRECHECKS_TABLE = Record<'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', PRECHECK>; + +/** A `ROUTE_HANDLER_METHOD` must take a `Request` and `meta` data and return a `Response`. */ export type ROUTE_HANDLER_METHOD = (request: Request, meta: Record) => Promise | Response; +/** A `ROUTE_HANDLER` can export methods for handling various HTTP requests. */ export interface ROUTE_HANDLER { PRECHECKS?: PRECHECKS_TABLE; GET?: ROUTE_HANDLER_METHOD; diff --git a/server.ts b/server.ts index 78d7cb8..9a58310 100644 --- a/server.ts +++ b/server.ts @@ -1,12 +1,21 @@ +/** + * SERVERUS SERVER module + * @module + */ + import * as colors from '@std/fmt/colors'; import * as fs from '@std/fs'; import * as path from '@std/path'; const DEFAULT_HANDLER_DIRECTORIES = [path.resolve(path.join(path.dirname(path.fromFileUrl(import.meta.url)), 'handlers'))]; +/** A `HANDLER` must take a `Request` and return a `Response` if it can handle it. */ type HANDLER = (request: Request) => Promise | Response | null | undefined; + +/** A `LOGGER` must take a `Request`, a `Response`, and a `processing_time` and log it. */ type LOGGER = (request: Request, response: Response, processing_time: number) => void | Promise; +/** A `HANDLER_MODULE` must export a default method and may export an unload method to be called at shutdown. */ interface HANDLER_MODULE { default: HANDLER; unload?: () => void; diff --git a/serverus.ts b/serverus.ts index 20e9527..9dc5de4 100644 --- a/serverus.ts +++ b/serverus.ts @@ -1,3 +1,8 @@ +/** + * Command line interface for SERVERUS + * @module + */ + import { parseArgs } from '@std/cli/parse-args'; import { SERVER } from './server.ts'; import * as path from '@std/path';