Spaces:
Configuration error
Configuration error
File size: 624 Bytes
3a25f97 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import http from "node:http";
export interface NodeApiHostOptions<THub> {
requestListener: http.RequestListener;
createHub: (server: http.Server) => THub;
}
export interface NodeApiHost<THub> {
server: http.Server;
hub: THub;
listen: (port: number, onListening?: () => void) => void;
}
export const createNodeApiHost = <THub>(options: NodeApiHostOptions<THub>): NodeApiHost<THub> => {
const server = http.createServer(options.requestListener);
const hub = options.createHub(server);
return {
server,
hub,
listen: (port, onListening) => {
server.listen(port, onListening);
},
};
}; |