123456789101112131415161718192021222324 |
- import express from "express";
- import { createServer } from "http";
- import { ModuleRpcServer } from "rpc_ts/lib/server";
- import { ModuleRpcProtocolServer } from "rpc_ts/lib/protocol/server";
- import { NoctBotService } from "@shared/rpc/backend";
- import { logger } from "./logging";
- const PORT = +(process.env.WEB_PORT ?? "8181");
- const app = express();
- const handler: ModuleRpcServer.ServiceHandlerFor<typeof NoctBotService> = {
- async getPing({ ping }): Promise<{ text: string }> {
- return { text: `pong: ${ping}` };
- }
- };
- app.use(ModuleRpcProtocolServer.registerRpcRoutes(NoctBotService, handler));
- export function startRpcServer(): void {
- logger.info(`Starting RPC at *:${PORT}`);
- createServer(app).listen(PORT);
- }
|