Skip to main content
Module

x/mith/mod.ts>Mith

A middleware framework for Deno's http/s server.
Latest
class Mith
import { Mith } from "https://deno.land/x/mith@v0.9.6/mod.ts";

A class which registers middleware (via .use()) and then processes inbound requests against that middleware (via .listen()).

Properties

private
middlewareStacks: MiddlewareStacks
private
PORT: number
optional
server: Server

Methods

private
getMiddlewareStack(stack: Stacks)

getMiddlewareStack based on the requested stack returns the correct middleware items

private
nextMiddleware(
request: IRequest,
response: IResponse,
stack: Stacks,
index: number,
next?: NextFunction,
error?: any,
)

nextMiddleware function will trigger the next middleware in line In case an error is passed it moves to the error middleware stack

private
nextStack(stack: Stacks)

Returns the next stack in line before > main > after || error > after

private
setupListener()

Listens to the async iterable server instance for incoming requests Runs the stack of middleware for each request

private
stackSendOrNext(
req: IRequest,
res: IResponse,
stack: Stacks,
next?: NextFunction,
error?: any,
)

Calls sendResponse in case Mith server is already setup Calls the next function in case this is a sub application Stops execution otherwise

after(middleware: Middleware | Middleware[])

Register middleware on the after stack.

before(middleware: Middleware | Middleware[])

Register middleware on the before stack.

Closes the ongoing server

mith.close()

dispatch(
request: IRequest,
response: IResponse,
stack: Stacks,
index?: number,
next?: NextFunction,
error?: any,
): void

Dispatch function will trigger the middleware in sequence based on the current stack

error(middleware: Middleware | Middleware[])

Register middleware to be used when next(error) is called.

listen(options?: string | HTTPOptions)

Create an HTTP server with given options

const options = { hostname: "localhost", port: 8000, }

mith.listen(options)

main(middleware: Middleware | Middleware[])

Register middleware on the main stack.

use(middleware: Middleware | Middleware[], stack?: Stacks)

Register middleware to be used with the application.