server/utils/server.ts

32 lines
1,008 B
TypeScript
Raw Normal View History

import type { ConfigSchema } from "@versia-server/config";
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({
2024-04-07 07:30:49 +02:00
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;
2024-04-07 07:30:49 +02:00
},
});