0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00

Add support for extra api routes (#3308)

Introduce new server section in Mastra to support server configuration.

```
server: {
    // replaces serverMiddlware
    middleware: [
      async (c, next) => {
        console.log("middleware", c.req.url);
        await next();
      },
    ],
    // collection of routes
    apiRoutes: [
      registerApiRoute("/cool/stuff", {
        method: "GET",
        openapi: {
          description: "Get API status",
          tags: ["system"],
          responses: {
            200: {
              description: "Success",
            },
          },
        },
        handler: (c) => {
          return c.json({ message: "Hello, world!" });
        },
      }),
      registerApiRoute("/cool/posts/:id", {
        method: "GET",
        handler: (c) => {
          const x = c.get("mastra");

          return c.json({ message: "Hello, world!", id: c.req.param("id") });
        },
      }),
    ],
  },
```
This commit is contained in:
Ward Peeters 2025-03-28 15:31:15 +01:00 • committed by GitHub
commit 304397c5fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 139 additions and 5 deletions