docs: improve docs a bit more

This commit is contained in:
Andy Burke 2025-06-19 15:55:35 -07:00
parent 58139b078d
commit b7011f9659
6 changed files with 38 additions and 1 deletions

View file

@ -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",

View file

@ -1,3 +1,8 @@
/**
* Default handler for returning Markdown as either HTML or raw Markdown.
* @module
*/
import * as path from '@std/path';
/**

View file

@ -1,3 +1,8 @@
/**
* Handles requests for static files.
* @module
*/
import * as path from '@std/path';
import * as media_types from '@std/media-types';

View file

@ -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<string, any>
) => undefined | Response | Promise<undefined | Response>;
/** 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<string, any>) => Promise<Response> | Response;
/** A `ROUTE_HANDLER` can export methods for handling various HTTP requests. */
export interface ROUTE_HANDLER {
PRECHECKS?: PRECHECKS_TABLE;
GET?: ROUTE_HANDLER_METHOD;

View file

@ -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> | 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<void>;
/** 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;

View file

@ -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';