Skip to content

Function: attachRoutePatchMiddleware()

attachRoutePatchMiddleware(app): void

Patches around @mastra/express’s custom-route dispatcher so the plugin’s custom API routes (e.g. historyRoute) work when MastraServer is hosted on an Express subapp mounted under a parent path (e.g. /api/mastra).

The adapter’s registerCustomApiRoutes matches against req.path (mount-relative, correct) but dispatches to its internal Hono mini-app using req.originalUrl, which still contains the parent mount prefix. The Hono app registers the literal route paths (for example /route/history), so the absolute URL never matches until we overwrite originalUrl for /route and /route/* to the mount-relative path.

Express

void