New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@leverage/plugin-http

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leverage/plugin-http

An HTTP plugin for Leverage

latest
npmnpm
Version
4.1.1
Version published
Maintainers
1
Created
Source

@leverage/plugin-http

A HTTP plugin for Leverage.

Install

# Using NPM
npm install @leverage/plugin-http

# Using Yarn
yarn add @leverage/plugin-http

Documentation

Plugin Install

To install the HTTP Plugin, add http to Leverage.

import { add } from "@leverage/core";
import { http } from "@leverage/plugin-http";

add(http);

Events

The HTTP Plugin can be configured using events. The server can also be told to start listening.

import { add, emit } from "@leverage/core";
import { http } from "@leverage/plugin-http";

add(http);

// Configure the Fastify instance
await emit("http:configure", {
    /*
     * All configuration options are passed directly to the Fastify server.
     * https://www.fastify.io/docs/latest/Server/
     */
    ignoreTrailingSlash: true,
});

// Tell the server to start listening on a port
await signal("http:listen", {
    port: 8080,
});

Components

A HTTP component holds configuration for a route.

import { useHTTP } from "@leverage/plugin-http";

export const init = () => {
    useHTTP({
        /*
         * All configuration options are passed directly to `fastify.route()`.
         * https://www.fastify.io/docs/latest/Routes/
         */
        path: "/hello-world",
        method: "GET",
    });
};

// Any Fastify handlers/callbacks are also passed to `fastify.route()`.
export const handler = (request, reply) => {
    /* ... */
};
export const preHandler = (request, reply) => {
    /* ... */
};
export const onSend = (request, reply) => {
    /* ... */
};

Additionally, connect-style middleware can be used by exporting a middleware function.

import { useHTTP } from "@leverage/plugin-http";
import cors from "cors";

export const init = () => {
    useHTTP();
};

export const middleware = cors();

Hooks

useHTTP

The useHTTP hook can be used to configure an HTTP component.

import { useHTTP } from "@leverage/plugin-http";

export const init = () => {
    useHTTP({
        /*
         * All configuration options are passed directly to `fastify.route()`.
         * https://www.fastify.io/docs/latest/Routes/
         */
        path: "/hello-world",
        method: "GET",
    });
};
import { useHTTP } from "@leverage/plugin-http";

export const init = () => {
    /*
     * When called without a config, the component is still configured for use
     *  with the HTTP plugin. This is useful when used for middleware with the
     *  `useMiddleware` hook.
     */
    useHTTP();
};

Keywords

leverage

FAQs

Package last updated on 09 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts