Skip to content

@donneko/tyoi-server / tyoi

Function: tyoi()

tyoi<RequestNameList, WebSocketNameList>(options): ShortHandler<RequestNameList, WebSocketNameList>

Defined in: short-handler/short-handler.ts:107

API と WebSocket の登録を簡潔に行うサーバーを作成します。 Creates a server with a compact API for registering HTTP and WebSocket handlers.

Type Parameters

RequestNameList

RequestNameList extends string = string

登録できる HTTP API キー(例: "GET:/health")。 / HTTP API keys that can be registered, such as "GET:/health".

WebSocketNameList

WebSocketNameList extends string = string

登録できる WebSocket パス。 / WebSocket paths that can be registered.

Parameters

options

ServerOptions

サーバー設定。root は必須です。 / Server options. root is required.

Returns

ShortHandler<RequestNameList, WebSocketNameList>

API 登録・起動・停止を行う簡易 API。 / A compact API for registration, startup, and shutdown.

Example

ts
type ApiKeys = "GET:/health";
type WebSocketKeys = "/events";

const app = tyoi<ApiKeys, WebSocketKeys>({
  root: import.meta.dirname,
  public: "../public/main",
});

app.get("/health", () => ({ status: "ok" }));
await app.start();