Skip to content

This is the Fastify module for ZyroHub ecosystem. It allows you to easily create a Fastify server and integrate it with @zyrohub/module-router.

License

Notifications You must be signed in to change notification settings

ZyroHub/module-fastify

Repository files navigation

ZyroHub - Fastify Module

This is the Fastify module for ZyroHub ecosystem. It allows you to easily create a Fastify server and integrate it with @zyrohub/module-router.

Table of Contents

Getting Started

To install the fastify module, use one of the following package managers:

NPM Repository

# npm
npm install @zyrohub/module-fastify
# yarn
yarn add @zyrohub/module-fastify
# pnpm
pnpm add @zyrohub/module-fastify
# bun
bun add @zyrohub/module-fastify

Required Dependencies

You also need to install fastify, @zyrohub/module-router and @zyrohub/core dependencies:

# npm
npm install fastify @zyrohub/module-router @zyrohub/core

# yarn
yarn add fastify @zyrohub/module-router @zyrohub/core

# pnpm
pnpm add fastify @zyrohub/module-router @zyrohub/core

# bun
bun add fastify @zyrohub/module-router @zyrohub/core

Using Module

import { Core } from '@zyrohub/core';
import { FastifyModule } from '@zyrohub/module-fastify';
import { RouterModule } from '@zyrohub/module-router';

const core = new Core({
	modules: [
		RouterModule.mount({
			// RouterModule options here (see @zyrohub/module-router documentation)
		}),
		FastifyModule.mount({
			port: 3000,
			host: 'localhost', // optional

			rawOptions: {
				// Fastify server options here (see https://www.fastify.io/docs/latest/Reference/Server/)
			},
			rawListenOptions: {
				// Fastify listen options here (see https://www.fastify.io/docs/latest/Reference/Server/#listen)
			},

			onSetup(server, core) {
				// called once the Fastify server is being set up and before registering routes
			}
		})
	]
});

core.init();

Declaring Request and Response types

// e.g., src/types/router.d.ts
import '@zyrohub/module-router';
import { FastifyReply, FastifyRequest } from 'fastify';

declare module '@zyrohub/module-router' {
	interface RouterGlobalInputs {
		request: FastifyRequest;
		response: FastifyReply;
	}
}

About

This is the Fastify module for ZyroHub ecosystem. It allows you to easily create a Fastify server and integrate it with @zyrohub/module-router.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published