docs: improve docs a bit more
This commit is contained in:
parent
58139b078d
commit
b7011f9659
6 changed files with 38 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@andyburke/serverus",
|
"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",
|
"license": "MIT",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./serverus.ts",
|
".": "./serverus.ts",
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Default handler for returning Markdown as either HTML or raw Markdown.
|
||||||
|
* @module
|
||||||
|
*/
|
||||||
|
|
||||||
import * as path from '@std/path';
|
import * as path from '@std/path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Handles requests for static files.
|
||||||
|
* @module
|
||||||
|
*/
|
||||||
|
|
||||||
import * as path from '@std/path';
|
import * as path from '@std/path';
|
||||||
import * as media_types from '@std/media-types';
|
import * as media_types from '@std/media-types';
|
||||||
|
|
||||||
|
|
|
@ -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 { walk } from '@std/fs';
|
||||||
import { delay } from '@std/async/delay';
|
import { delay } from '@std/async/delay';
|
||||||
import * as path from '@std/path';
|
import * as path from '@std/path';
|
||||||
import { getCookies } from '@std/http/cookie';
|
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 = (
|
export type PRECHECK = (
|
||||||
request: Request,
|
request: Request,
|
||||||
meta: Record<string, any>
|
meta: Record<string, any>
|
||||||
) => undefined | Response | Promise<undefined | Response>;
|
) => 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>;
|
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;
|
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 {
|
export interface ROUTE_HANDLER {
|
||||||
PRECHECKS?: PRECHECKS_TABLE;
|
PRECHECKS?: PRECHECKS_TABLE;
|
||||||
GET?: ROUTE_HANDLER_METHOD;
|
GET?: ROUTE_HANDLER_METHOD;
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
|
/**
|
||||||
|
* SERVERUS SERVER module
|
||||||
|
* @module
|
||||||
|
*/
|
||||||
|
|
||||||
import * as colors from '@std/fmt/colors';
|
import * as colors from '@std/fmt/colors';
|
||||||
import * as fs from '@std/fs';
|
import * as fs from '@std/fs';
|
||||||
import * as path from '@std/path';
|
import * as path from '@std/path';
|
||||||
|
|
||||||
const DEFAULT_HANDLER_DIRECTORIES = [path.resolve(path.join(path.dirname(path.fromFileUrl(import.meta.url)), 'handlers'))];
|
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;
|
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>;
|
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 {
|
interface HANDLER_MODULE {
|
||||||
default: HANDLER;
|
default: HANDLER;
|
||||||
unload?: () => void;
|
unload?: () => void;
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Command line interface for SERVERUS
|
||||||
|
* @module
|
||||||
|
*/
|
||||||
|
|
||||||
import { parseArgs } from '@std/cli/parse-args';
|
import { parseArgs } from '@std/cli/parse-args';
|
||||||
import { SERVER } from './server.ts';
|
import { SERVER } from './server.ts';
|
||||||
import * as path from '@std/path';
|
import * as path from '@std/path';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue