Files
sign/apps/remix/server/router.ts

51 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-01-02 15:33:37 +11:00
import { Hono } from 'hono';
import { contextStorage } from 'hono/context-storage';
import { tsRestHonoApp } from '@documenso/api/hono';
import { auth } from '@documenso/auth/server';
import { API_V2_BETA_URL } from '@documenso/lib/constants/app';
import { jobsClient } from '@documenso/lib/jobs/client';
import { openApiDocument } from '@documenso/trpc/server/open-api';
import { filesRoute } from './api/files';
import { type AppContext, appContext } from './context';
2025-02-26 19:42:42 +11:00
import { appMiddleware } from './middleware';
2025-01-02 15:33:37 +11:00
import { openApiTrpcServerHandler } from './trpc/hono-trpc-open-api';
import { reactRouterTrpcServer } from './trpc/hono-trpc-remix';
export interface HonoEnv {
Variables: {
context: AppContext;
};
}
const app = new Hono<HonoEnv>();
/**
2025-02-19 18:04:36 +11:00
* Attach session and context to requests.
2025-01-02 15:33:37 +11:00
*/
2025-02-19 18:04:36 +11:00
app.use(contextStorage());
app.use(appContext);
2025-01-02 15:33:37 +11:00
2025-02-26 19:42:42 +11:00
/**
* RR7 app middleware.
*/
app.use('*', appMiddleware);
2025-01-02 15:33:37 +11:00
// Auth server.
app.route('/api/auth', auth);
// Files route.
app.route('/api/files', filesRoute);
2025-02-19 18:04:36 +11:00
// API servers.
2025-01-02 15:33:37 +11:00
app.route('/api/v1', tsRestHonoApp);
app.use('/api/jobs/*', jobsClient.getApiHandler());
app.use('/api/trpc/*', reactRouterTrpcServer);
// Unstable API server routes. Order matters for these two.
app.get(`${API_V2_BETA_URL}/openapi.json`, (c) => c.json(openApiDocument));
2025-02-19 18:04:36 +11:00
app.use(`${API_V2_BETA_URL}/*`, async (c) => openApiTrpcServerHandler(c));
2025-01-02 15:33:37 +11:00
export default app;