server/utils/server.ts
Jesse Wierzbinski aff51b651c
Some checks failed
Mirror to Codeberg / Mirror (push) Failing after 0s
Test Publish / build (client) (push) Failing after 0s
Test Publish / build (sdk) (push) Failing after 0s
refactor: ♻️ Rewrite logging logic into a unified package
2025-06-22 18:43:03 +02:00

32 lines
1,015 B
TypeScript

import type { ConfigSchema } from "@versia-server/config/schema";
import { debugResponse } from "@versia-server/kit/api";
import { type Server, serve } from "bun";
import type { Hono } from "hono";
import type { z } from "zod";
import type { HonoEnv } from "~/types/api";
export const createServer = (
config: z.infer<typeof ConfigSchema>,
app: Hono<HonoEnv>,
): Server =>
serve({
port: config.http.bind_port,
reusePort: true,
tls: config.http.tls
? {
key: config.http.tls.key.file,
cert: config.http.tls.cert.file,
passphrase: config.http.tls.passphrase,
ca: config.http.tls.ca?.file,
}
: undefined,
hostname: config.http.bind,
async fetch(req, server): Promise<Response> {
const output = await app.fetch(req, { ip: server.requestIP(req) });
await debugResponse(output.clone());
return output;
},
});