-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
62 lines (55 loc) · 1.85 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Hono, type Context } from "hono";
import { APP_DESCRIPTION, APP_VERSION, config } from "./src/config.js";
import { logger } from './src/logger.js';
import { openAPISpecs } from 'hono-openapi';
import routes from './src/routes/index.js';
import { APIErrorResponse } from "./src/utils.js";
import { startMcpServer } from "./src/mcp/index.js";
// Start MCP server
await startMcpServer().catch((error) => {
console.error("Error starting MCP server:", error);
});
const app = new Hono();
// -----------
// --- API ---
// -----------
app.route('/', routes);
// ------------
// --- Docs ---
// ------------
app.get("/", () => new Response(Bun.file("./public/index.html")));
app.get("/favicon.svg", () => new Response(Bun.file("./public/favicon.svg")));
app.get('/openapi', openAPISpecs(app, {
documentation: {
info: {
title: 'Token API (Beta)',
version: APP_VERSION,
description: 'Power your apps & AI agents with real-time token data.',
},
servers: [
{ url: `https://token-api.service.pinax.network`, description: `${APP_DESCRIPTION} - Production` },
{ url: `http://localhost:${config.port}`, description: `${APP_DESCRIPTION} - Local` },
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
}
}
},
}));
// Tracking all incoming requests
app.use(async (c: Context, next) => {
const pathname = c.req.path;
logger.trace(`Incoming request: [${pathname}]`);
await next();
});
// 404 NOT FOUND
app.notFound((c: Context) => APIErrorResponse(c, 404, "route_not_found", `Path not found: ${c.req.method} ${c.req.path}`));
export default {
...app,
idleTimeout: config.requestIdleTimeout
};