Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
change how the app connection and secret sync route are created
adilson94e4fc4d3370
diff --git a/backend/src/server/lib/boot-yield.ts b/backend/src/server/lib/boot-yield.tsdeleted file mode 100644index 82011fab98..0000000000--- a/backend/src/server/lib/boot-yield.ts+++ /dev/null@@ -1,14 +0,0 @@-// Fastify drains every encapsulated context's onReady phase synchronously through avvio's-// ready queue. With hundreds of per-destination route contexts that synchronous fastq drain-// recurses once per context and can blow V8's call stack at boot. A no-op async onReady hook-// makes this context's ready task resolve on a microtask, letting the stack unwind between-// sibling contexts and keeping boot recursion bounded.-export const addBootYieldHook = (server: FastifyZodProvider) => {- server.addHook("onReady", async () => {});-};--export const withBootYield =- (plugin: (server: FastifyZodProvider) => Promise<void>) => async (server: FastifyZodProvider) => {- addBootYieldHook(server);- await plugin(server);- };diff --git a/backend/src/server/lib/with-route-prefix.ts b/backend/src/server/lib/with-route-prefix.tsnew file mode 100644index 0000000000..8f5e8a2cf5--- /dev/null+++ b/backend/src/server/lib/with-route-prefix.ts@@ -0,0 +1,12 @@+// Hands a plugin a server whose route() bakes `prefix` into the URL instead of relying on an+// encapsulated context. Avoids creating a Fastify context per destination (hundreds at boot),+// which previously overflowed the call stack during the onReady walk. Safe only for plugins+// that exclusively call route() — no addHook/decorate/register (true for all destination routers).+export const withRoutePrefix = (server: FastifyZodProvider, prefix: string): FastifyZodProvider => {+ const scoped: FastifyZodProvider = Object.create(server) as FastifyZodProvider;+ scoped.route = ((opts: Parameters<FastifyZodProvider["route"]>[0]) => {+ server.route({ ...opts, url: opts.url === "/" ? prefix : `${prefix}${opts.url}` });+ return scoped;+ }) as FastifyZodProvider["route"];+ return scoped;+};diff --git a/backend/src/server/routes/v1/index.ts b/backend/src/server/routes/v1/index.tsindex 0c4ee1fdd7..c39c843055 100644--- a/backend/src/server/routes/v1/index.ts+++ b/backend/src/server/routes/v1/index.ts@@ -1,5 +1,5 @@import { BadRequestError } from "@app/lib/errors";-import { withBootYield } from "@app/server/lib/boot-yield";+import { withRoutePrefix } from "@app/server/lib/with-route-prefix";import { injectCertManagerProjectId } from "@app/server/plugins/inject-cert-manager-project-id";import {APP_CONNECTION_REGISTER_ROUTER_MAP,@@ -323,8 +323,11 @@ export const registerV1Routes = async (server: FastifyZodProvider) => {await appConnectionRouter.register(registerAppConnectionRouter);// register service specific endpoints (app-connections/aws, app-connections/github, etc.)+ // routes are registered on the shared context with the destination baked into the URL —+ // a register({ prefix }) per destination would create hundreds of encapsulated contexts+ // and overflow the call stack during Fastify's onReady boot walkfor await (const [app, router] of Object.entries(APP_CONNECTION_REGISTER_ROUTER_MAP)) {- await appConnectionRouter.register(withBootYield(router), { prefix: `/${app}` });+ await router(withRoutePrefix(appConnectionRouter as unknown as FastifyZodProvider, `/${app}`));}},{ prefix: "/app-connections" }@@ -336,8 +339,9 @@ export const registerV1Routes = async (server: FastifyZodProvider) => {await secretSyncRouter.register(registerSecretSyncRouter);// register service specific secret sync endpoints (secret-syncs/aws-parameter-store, secret-syncs/github, etc.)+ // see app-connections above: routes share one context with the destination baked into the URLfor await (const [destination, router] of Object.entries(SECRET_SYNC_REGISTER_ROUTER_MAP)) {- await secretSyncRouter.register(withBootYield(router), { prefix: `/${destination}` });+ await router(withRoutePrefix(secretSyncRouter as unknown as FastifyZodProvider, `/${destination}`));}},{ prefix: "/secret-syncs" }