TofuStack/src/lib/server/api/index.ts

47 lines
2.5 KiB
TypeScript
Raw Normal View History

2024-05-25 06:02:26 +00:00
import 'reflect-metadata';
import './providers';
import { Hono } from 'hono';
import { hc } from 'hono/client';
import { container } from 'tsyringe';
2024-06-25 16:50:52 +00:00
import { validateAuthSession, verifyOrigin } from './middleware/auth.middleware';
2024-05-25 06:02:26 +00:00
import { IamController } from './controllers/iam.controller';
import { config } from './common/config';
2024-05-25 06:02:26 +00:00
/* -------------------------------------------------------------------------- */
/* Client Request */
/* ------------------------------------ ▲ ----------------------------------- */
/* ------------------------------------ | ----------------------------------- */
/* ------------------------------------ ▼ ----------------------------------- */
/* Controller */
/* ---------------------------- (Request Routing) --------------------------- */
/* ------------------------------------ ▲ ----------------------------------- */
/* ------------------------------------ | ----------------------------------- */
/* ------------------------------------ ▼ ----------------------------------- */
/* Service */
/* ---------------------------- (Business logic) ---------------------------- */
/* ------------------------------------ ▲ ----------------------------------- */
/* ------------------------------------ | ----------------------------------- */
/* ------------------------------------ ▼ ----------------------------------- */
/* Repository */
/* ----------------------------- (Data storage) ----------------------------- */
2024-05-25 06:02:26 +00:00
/* -------------------------------------------------------------------------- */
/* ----------------------------------- Api ---------------------------------- */
2024-05-25 06:02:26 +00:00
const app = new Hono().basePath('/api');
/* --------------------------- Global Middlewares --------------------------- */
2024-06-25 02:45:00 +00:00
app.use(verifyOrigin).use(validateAuthSession);
/* --------------------------------- Routes --------------------------------- */
2024-05-25 06:02:26 +00:00
const routes = app
.route('/iam', container.resolve(IamController).routes())
2024-06-25 02:45:00 +00:00
2024-05-25 06:02:26 +00:00
/* -------------------------------------------------------------------------- */
/* Exports */
/* -------------------------------------------------------------------------- */
export const rpc = hc<typeof routes>(config.ORIGIN);
2024-05-25 06:02:26 +00:00
export type ApiClient = typeof rpc;
export type ApiRoutes = typeof routes;
export { app };