refactor: share the PRECHECK type at the top level
This commit is contained in:
parent
41c7802a36
commit
18b58ba94a
4 changed files with 9 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@andyburke/serverus",
|
"name": "@andyburke/serverus",
|
||||||
"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.",
|
"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.11.3",
|
"version": "0.11.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./serverus.ts",
|
".": "./serverus.ts",
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import * as fs from '@std/fs';
|
import * as fs from '@std/fs';
|
||||||
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';
|
||||||
import { SERVER } from '../server.ts';
|
import { PRECHECK, SERVER } from '../server.ts';
|
||||||
import { getCookies } from '@std/http/cookie';
|
import { getCookies } from '@std/http/cookie';
|
||||||
|
|
||||||
let PUT_PATHS_ALLOWED: string[] | undefined = undefined;
|
let PUT_PATHS_ALLOWED: string[] | undefined = undefined;
|
||||||
|
@ -18,7 +18,6 @@ export type HANDLER_METHOD = (
|
||||||
normalized_path: string,
|
normalized_path: string,
|
||||||
server: SERVER
|
server: SERVER
|
||||||
) => Promise<Response | undefined> | Response | undefined;
|
) => Promise<Response | undefined> | Response | undefined;
|
||||||
export type PRECHECK = (request: Request, meta: Record<string, any>) => Promise<Response> | Response | undefined;
|
|
||||||
export const PRECHECKS: Partial<Record<HTTP_METHOD, PRECHECK[]>> = {};
|
export const PRECHECKS: Partial<Record<HTTP_METHOD, PRECHECK[]>> = {};
|
||||||
export const HANDLERS: Partial<Record<HTTP_METHOD, HANDLER_METHOD>> = {
|
export const HANDLERS: Partial<Record<HTTP_METHOD, HANDLER_METHOD>> = {
|
||||||
HEAD: async (_request: Request, normalized_path: string, _server: SERVER): Promise<Response | undefined> => {
|
HEAD: async (_request: Request, normalized_path: string, _server: SERVER): Promise<Response | undefined> => {
|
||||||
|
|
|
@ -8,12 +8,7 @@ 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';
|
||||||
|
import { PRECHECK } from '@andyburke/serverus/server';
|
||||||
/** 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 an array of `PRECHECK`s to be run. */
|
/** A `PRECHECK_TABLE` maps from HTTP methods to an array of `PRECHECK`s to be run. */
|
||||||
export type PRECHECKS_TABLE = Record<'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', PRECHECK[]>;
|
export type PRECHECKS_TABLE = Record<'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', PRECHECK[]>;
|
||||||
|
|
|
@ -56,6 +56,12 @@ export const DEFAULT_SERVER_OPTIONS: SERVER_OPTIONS = {
|
||||||
logging: true
|
logging: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 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>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method LOG_REQUEST Default request logger.
|
* @method LOG_REQUEST Default request logger.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue