0.2.1 • Published 6 months ago

fastify-next v0.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
6 months ago

fastify-next

Fastify plugin for Next.js, the React framework.

This is an alternative to the official @fastify/nextjs plugin. See comparison.

Install

npm install fastify-next next react react-dom

Basic Usage

If you want your Fastify server to work similar to the Next.js CLI, do the following:

import fastify from 'fastify';
import FastifyNext from 'fastify-next';

// Registering the plugin adds the 'next' decorator
await fastify.register(FastifyNext);

// Pass '*' to handle all incoming requests with Next.js
fastify.next('*');

Comparison with @fastify/nextjs

For the most part, this package will work as a drop-in replacement for @fastify/nextjs. However, there are a few differences.

_next/* route handling

By default @fastify/nextjs handles all incoming requests to /_next/*. To mimic this behaviour with fastify-next, add the following:

fastify.next('/_next/*');

under-pressure

The @fastify/nextjs plugin includes under-pressure as a dependency which can be enabled by passing the underPressure: true option. This package does not currently include support for under-pressure.

Startup time during local dev

Next.js type-checks and compiles the application when the dev server first starts. The @fastify/nextjs plugin waits for the Next.js server to finish doing this before resolving plugin initialization. This can lead to plugin timeout in large Next.js projects.

This plugin initializes immediately, allowing you to make requests to the Fastify server immediately, but will wait for Next.js to complete startup before handling incoming requests.

Note: this has no effect in production. The dev server can be enabled using the dev: true option or setting NODE_ENV=development in the environment.

0.2.1

6 months ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago