@applicazza/fastify-nextjs
is a plugin for serving Next.js requests
via Fastify.
This project is yet to reach stable state. You may help by contributing and testing it.
Original fastify-nextjs doesn't pass response through Fastify's pipeline thus hooks that you may need won't work. This package is using JavaScript's Proxy to intercept calls to NodeJs http.ServerResponse and pass it to Fastify.
yarn add @applicazza/fastify-nextjs
yarn add fastify-static
module.exports = {
compress: false,
};
import createFastify from 'fastify';
import fastifyNextJs from '@applicazza/fastify-nextjs';
const dev = process.env.NODE_ENV !== 'production';
const fastify = createFastify();
fastify.register(fastifyNextJs, {
dev,
});
await fastify.after();
fastify.passNextJsRequests();
await fastify.listen(0);
import createFastify from 'fastify';
import fastifyNextJs from '@applicazza/fastify-nextjs';
const dev = process.env.NODE_ENV !== 'production';
const fastify = createFastify();
fastify.register(fastifyNextJs, {
dev,
});
await fastify.after();
fastify.passNextJsDataRequests();
fastify.passNextJsImageRequests();
if (dev) {
fastify.passNextJsDevRequests();
} else {
fastify.passNextJsStaticRequests();
}
fastify.passNextJsPageRequests();
await fastify.listen(0);
interface FastifyNextJsOptions {
basePath?: string;
dev?: boolean;
dir?: string;
}
interface FastifyNextJsDecoratorArguments {
logLevel?: LogLevel;
}
interface FastifyInstance {
nextJsProxyRequestHandler: (request: FastifyRequest, reply: FastifyReply) => void;
nextJsRawRequestHandler: (request: FastifyRequest, reply: FastifyReply) => void;
nextServer: NextServer;
passNextJsRequests: (args?: FastifyNextJsDecoratorArguments) => void;
passNextJsDataRequests: (args?: FastifyNextJsDecoratorArguments) => void;
passNextJsDevRequests: (args?: FastifyNextJsDecoratorArguments) => void;
passNextJsImageRequests: (args?: FastifyNextJsDecoratorArguments) => void;
passNextJsPageRequests: (args?: FastifyNextJsDecoratorArguments) => void;
passNextJsStaticRequests: (args?: FastifyNextJsDecoratorArguments) => void;
}
yarn build
yarn test
Licensed under MIT.