@mastra/hono 1.4.8-alpha.0 → 1.4.8-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -943,12 +943,9 @@ var MastraServer = class extends MastraServer$1 {
943
943
  );
944
944
  }
945
945
  async registerCustomApiRoutes() {
946
- const routes = this.customApiRoutes ?? this.mastra.getServer()?.apiRoutes;
947
- if (!routes || routes.length === 0) return;
946
+ if (!await this.buildCustomRouteHandler()) return;
947
+ const routes = this.customApiRoutes ?? this.mastra.getServer()?.apiRoutes ?? [];
948
948
  for (const route of routes) {
949
- const handler = "handler" in route && route.handler ? route.handler : "createHandler" in route ? await route.createHandler({ mastra: this.mastra }) : void 0;
950
- if (!handler) continue;
951
- const middlewares = [];
952
949
  const serverRoute = {
953
950
  method: route.method,
954
951
  path: route.path,
@@ -957,7 +954,7 @@ var MastraServer = class extends MastraServer$1 {
957
954
  },
958
955
  requiresAuth: route.requiresAuth
959
956
  };
960
- middlewares.push(async (c, next) => {
957
+ const routeHandler = async (c) => {
961
958
  const authError = await this.checkRouteAuth(serverRoute, {
962
959
  path: c.req.path,
963
960
  method: c.req.method,
@@ -984,14 +981,24 @@ var MastraServer = class extends MastraServer$1 {
984
981
  }
985
982
  }
986
983
  }
987
- return next();
988
- });
989
- if (route.middleware) {
990
- middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
991
- }
992
- const allHandlers = [...middlewares, handler];
984
+ const reqHeaders = {};
985
+ c.req.raw.headers.forEach((v, k) => {
986
+ reqHeaders[k] = v;
987
+ });
988
+ const response = await this.handleCustomRouteRequest(
989
+ c.req.url,
990
+ c.req.method,
991
+ reqHeaders,
992
+ c.req.raw.body,
993
+ c.get("requestContext")
994
+ );
995
+ if (!response) {
996
+ return c.json({ error: "Not Found" }, 404);
997
+ }
998
+ return response;
999
+ };
993
1000
  const method = route.method.toLowerCase();
994
- this.app[method](route.path, allHandlers[0], ...allHandlers.slice(1));
1001
+ this.app[method](route.path, routeHandler);
995
1002
  }
996
1003
  }
997
1004
  registerContextMiddleware() {