fastify
介绍
nest默认express
集成 Fastify 可显著提升性能
使用
npm install @nestjs/platform-fastify fastify
main.ts
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
区别
const response = ctx.getResponse<FastifyReply>();
const request = ctx.getRequest<FastifyRequest>();
静态资源
@fastify/static
await app.register(require('@fastify/static'), {
root: path.join(process.cwd(), 'public'),
prefix: '/static/',
});
文件放在public下,请求时加static前缀
http:
待探索
HTTPS 支持
Schema 验证
生命周期钩子(Hooks)
速率限制
@fastify/rate-limit
JWT 认证优化
@fastify/jwt
连接池优化
fastify-postgres
流式响应处理
集群模式启动