@kagchi/fasting
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published
Logo

@kagchi/fasting

A Better Fastify auto loads for Routes & Prehandlers

GitHub Discord

Installation

pnpm

pnpm add @kagchi/fasting

npm

npm i @kagchi/fasting

yarn

yarn add @kagchi/fasting

Example Use

Main file

src/index.ts

import { fasting } from "@kagchi/fasting";
import fastify from "fastify";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";

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

await fastifyApp.register(fasting, {
    basePath: resolve(dirname(fileURLToPath(import.meta.url)))
});

await fastifyApp.listen({ port: 3_000 })
    .then(() => console.log("Server is running on port 3000"))
    .catch(() => console.log("Server failed to start"));

Create routes folder & Create root route

src/routes/index.ts

import type { RouteOptions } from "@kagchi/fasting";
import { Route } from "@kagchi/fasting";
import type { LoaderPieceContext } from "@sapphire/pieces";
import type { FastifyReply, FastifyRequest } from "fastify";

export class Root extends Route {
    public constructor(context: LoaderPieceContext, options: RouteOptions) {
        super(context, {
            ...options,
            method: "GET",
            path: "/"
        });
    }

    public run(request: FastifyRequest, response: FastifyReply): FastifyReply {
        return response.send("Hello, world!");
    }
}

Package Sidebar

Install

npm i @kagchi/fasting

Weekly Downloads

135

Version

2.0.0

License

GPL-3.0

Unpacked Size

73.1 kB

Total Files

45

Last publish

Collaborators

  • kagchi