From 84e2e4f5adb4b2c5a70180861813ecd5121cc776 Mon Sep 17 00:00:00 2001 From: Arnaud Moncel Date: Wed, 18 May 2022 17:08:56 +0200 Subject: [PATCH 1/2] fix(agent): import fastify/express only if needed --- packages/agent/src/builder/agent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/agent/src/builder/agent.ts b/packages/agent/src/builder/agent.ts index ffc51d0944..d10ca054da 100644 --- a/packages/agent/src/builder/agent.ts +++ b/packages/agent/src/builder/agent.ts @@ -9,7 +9,6 @@ import { import { writeFile } from 'fs/promises'; import Koa from 'koa'; import Router from '@koa/router'; -import fastifyExpress from '@fastify/express'; import http from 'http'; import { AgentOptions } from '../types'; @@ -236,6 +235,7 @@ export default class AgentBuilder { } catch (e) { // 'fastify 3' if (e.code === 'FST_ERR_MISSING_MIDDLEWARE') { + const fastifyExpress = import('@fastify/express'); fastify .register(fastifyExpress) .then(() => { From db926d02ff0182627f8c562a0b48b152d428d266 Mon Sep 17 00:00:00 2001 From: Arnaud Moncel Date: Wed, 18 May 2022 17:41:40 +0200 Subject: [PATCH 2/2] chore: improve code --- packages/agent/src/builder/agent.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/agent/src/builder/agent.ts b/packages/agent/src/builder/agent.ts index d10ca054da..adcd277125 100644 --- a/packages/agent/src/builder/agent.ts +++ b/packages/agent/src/builder/agent.ts @@ -235,9 +235,8 @@ export default class AgentBuilder { } catch (e) { // 'fastify 3' if (e.code === 'FST_ERR_MISSING_MIDDLEWARE') { - const fastifyExpress = import('@fastify/express'); fastify - .register(fastifyExpress) + .register(import('@fastify/express')) .then(() => { fastify.use('/forest', callback); })