mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 56s
Build Docker Images / lint (push) Failing after 10s
Build Docker Images / check (push) Failing after 11s
Build Docker Images / tests (push) Failing after 6s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / build (push) Failing after 5s
Mirror to Codeberg / Mirror (push) Failing after 1s
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Nix Build / check (push) Failing after 5s
33 lines
1 KiB
TypeScript
33 lines
1 KiB
TypeScript
import type { OpenAPIHono, z } from "@hono/zod-openapi";
|
|
import type { Server } from "bun";
|
|
import type { ConfigSchema } from "~/classes/config/schema.ts";
|
|
import type { HonoEnv } from "~/types/api";
|
|
import { debugResponse } from "./api.ts";
|
|
|
|
export const createServer = (
|
|
config: z.infer<typeof ConfigSchema>,
|
|
app: OpenAPIHono<HonoEnv>,
|
|
): Server =>
|
|
Bun.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) });
|
|
|
|
if (config.logging.types.responses) {
|
|
await debugResponse(output.clone());
|
|
}
|
|
|
|
return output;
|
|
},
|
|
});
|