Code Monkey home page Code Monkey logo

middleware's Introduction

oak middleware

ci deno doc

A collection of middleware for the oak framework.

Usage

Each middleware has its own module, as well as all the middleware being via the root mod.ts. If you just want everything, you can simply import the mod.ts, for example:

import * as oakMiddleware from "https://deno.land/x/oak_middleware/mod.ts";
import { Application } from "https://deno.land/x/oak/mod.ts";

const app = new Application();

app.use(oakMiddleware.responseTimeHeader);

Also consider using a tagged version of the middleware so that changes to the main branch won't provide unexpected results in your code. For example, to use version v0.1.0 you would do the following:

import * as oakMiddleware from "https://deno.land/x/[email protected]/mod.ts";

If you just want specific middleware, you can just import it from its module:

import { responseTimeHeader } from "https://deno.land/x/oak_middleware/observability/response_time_header.ts";

If you want to manage all your external dependencies in one place, just follow the convention of deps.ts and re-export what you want:

export { responseTimeHeader } from "https://deno.land/x/[email protected]/observability/response_time_header.ts";
export { Application } from "https://deno.land/x/[email protected]/mod.ts";

And then in your other modules, just import from deps.ts:

import { Application, responseTimeHeader } from "./deps.ts";

const app = new Application();
app.use(responseTimeHeader);
// ...
await app.listen({ port: 80 });

Middleware

This section contains middleware that is intended to be used with the .use() method on the application.

Observability

This is middleware that is used for instrumentation and observability of a server created with oak.

responseTimeHeader

A middleware that will set the response time for other middleware in milliseconds as X-Response-Time which can be used for diagnostics and other instrumentation of an application. Utilise the middleware before the "real" processing occurs.

import { responseTimeHeader } from "https://deno.land/x/oak-middleware/mod.ts";
import { Application } from "https://deno.land/x/oak/mod.ts";

const app = new App();
app.use(responseTimeHeader);

// other middleware

await app.listen(":80");

Router Middleware

This section contains middleware designed to work with the oak Router.


Copyright 2020 the oak authors. All rights reserved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.