mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
refactor(api): ♻️ Use OpenAPIHono instead of Hono in preparation for future changes
This commit is contained in:
parent
3c1b330d4b
commit
df466ecaa0
4
app.ts
4
app.ts
|
|
@ -1,8 +1,8 @@
|
||||||
import { sentry } from "@/sentry";
|
import { sentry } from "@/sentry";
|
||||||
import { Hono } from "@hono/hono";
|
|
||||||
import { cors } from "@hono/hono/cors";
|
import { cors } from "@hono/hono/cors";
|
||||||
import { prettyJSON } from "@hono/hono/pretty-json";
|
import { prettyJSON } from "@hono/hono/pretty-json";
|
||||||
import { secureHeaders } from "@hono/hono/secure-headers";
|
import { secureHeaders } from "@hono/hono/secure-headers";
|
||||||
|
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
/* import { prometheus } from "@hono/prometheus";
|
/* import { prometheus } from "@hono/prometheus";
|
||||||
*/ import { getLogger } from "@logtape/logtape";
|
*/ import { getLogger } from "@logtape/logtape";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { config } from "~/packages/config-manager/index";
|
||||||
|
|
@ -18,7 +18,7 @@ import type { ApiRouteExports } from "./types/api";
|
||||||
export const appFactory = async () => {
|
export const appFactory = async () => {
|
||||||
const serverLogger = getLogger("server");
|
const serverLogger = getLogger("server");
|
||||||
|
|
||||||
const app = new Hono({
|
const app = new OpenAPIHono({
|
||||||
strict: false,
|
strict: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@
|
||||||
"@hackmd/markdown-it-task-lists": "^2.1.4",
|
"@hackmd/markdown-it-task-lists": "^2.1.4",
|
||||||
"@hono/hono": "npm:@jsr/hono__hono@4.5.9",
|
"@hono/hono": "npm:@jsr/hono__hono@4.5.9",
|
||||||
"@hono/prometheus": "^1.0.1",
|
"@hono/prometheus": "^1.0.1",
|
||||||
|
"@hono/zod-openapi": "^0.16.0",
|
||||||
"@hono/zod-validator": "^0.2.2",
|
"@hono/zod-validator": "^0.2.2",
|
||||||
"@inquirer/confirm": "^3.1.22",
|
"@inquirer/confirm": "^3.1.22",
|
||||||
"@inquirer/input": "^2.2.9",
|
"@inquirer/input": "^2.2.9",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { Hono } from "@hono/hono";
|
|
||||||
import type { RouterRoute } from "@hono/hono/types";
|
import type { RouterRoute } from "@hono/hono/types";
|
||||||
|
import type { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import type {
|
import type {
|
||||||
Delete,
|
Delete,
|
||||||
Follow,
|
Follow,
|
||||||
|
|
@ -49,7 +49,7 @@ export interface ApiRouteExports {
|
||||||
query?: z.AnyZodObject;
|
query?: z.AnyZodObject;
|
||||||
body?: z.AnyZodObject;
|
body?: z.AnyZodObject;
|
||||||
};
|
};
|
||||||
default: (app: Hono) => RouterRoute;
|
default: (app: OpenAPIHono) => RouterRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type KnownEntity =
|
export type KnownEntity =
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import type { Context, Hono } from "@hono/hono";
|
import type { Context } from "@hono/hono";
|
||||||
import { createMiddleware } from "@hono/hono/factory";
|
import { createMiddleware } from "@hono/hono/factory";
|
||||||
import { validator } from "@hono/hono/validator";
|
import { validator } from "@hono/hono/validator";
|
||||||
|
import type { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import { getLogger } from "@logtape/logtape";
|
import { getLogger } from "@logtape/logtape";
|
||||||
import { extractParams, verifySolution } from "altcha-lib";
|
import { extractParams, verifySolution } from "altcha-lib";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
|
@ -46,7 +47,7 @@ export const applyConfig = (routeMeta: ApiRouteMetadata) => {
|
||||||
|
|
||||||
export const apiRoute = (
|
export const apiRoute = (
|
||||||
fn: (
|
fn: (
|
||||||
app: Hono /* <{
|
app: OpenAPIHono /* <{
|
||||||
Bindings: {};
|
Bindings: {};
|
||||||
}> */,
|
}> */,
|
||||||
) => void,
|
) => void,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import type { Hono } from "@hono/hono";
|
import type { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import type { Config } from "~/packages/config-manager/config.type";
|
import type { Config } from "~/packages/config-manager/config.type";
|
||||||
|
|
||||||
export const createServer = (config: Config, app: Hono) =>
|
export const createServer = (config: Config, app: OpenAPIHono) =>
|
||||||
Bun.serve({
|
Bun.serve({
|
||||||
port: config.http.bind_port,
|
port: config.http.bind_port,
|
||||||
reusePort: true,
|
reusePort: true,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue