🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

fastify-warmup

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-warmup

fastify warmup plugin

0.0.8
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

fastify-warmup

A library used to warmup fastify server before call .listen();

how to use

function fastifyWarmup(fastify: FastifyInstance, conf: WarmupConf): void

quick start

npm i fastify-warmup
import fastify from 'fastify';
import {fastifyWarmup} from 'fastify-warmup';

const app = fastify({logger: true});

(async () => {
    app.get('/a', async (req, rep) => {
    });
    app.get('/b', async (req, rep) => {
    });

    // will run after fastify.ready()
    await fastifyWarmup(app, {
        warmupData: {
            '/a': ['a'],
            '/b': 'b.json'
        },
        basePath: 'path/to/warmupBasePath'
    });

    const address = await app.listen(3001);
})();

options

interface WarmupConf {
    warmupData: Record<string, string[] | string>;

    /**
     * warmup tasks will be split to groups
     * [maxConcurrent]s per group
     */
    maxConcurrent?: number;
    timeout?: number;

    /**
     * all the files/folders in warmupData
     * will find based on basePath.
     */
    basePath: string;
}

The key of warmupData is the request url.

the Value of warmupData can be a string or string[], which can represents:

  • A folder. will load a the files with extension .json in that folder.
  • A file. must be end with .json

the .json file, which is the warmup data, can be:

{
    "method": "get" | "post" | ...;
    "query": Object;
    "payload": Object;
    "headers": Object;
    "cookies": Object;
}

FAQs

Package last updated on 20 Apr 2021

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