UNPKG

tools-mock

Version:

A node.js mock tool to quickly start the server via http

50 lines (49 loc) 1.09 kB
/// <reference types="node" /> import * as http from 'http'; import CMockConfig from './CMockConfig'; import * as WebSocket from 'ws'; type pathItemData = { req: http.IncomingMessage; ws: WebSocket; /** * 连接参数对象->{token:'666'} * 如/games?url=123&token=233 -> {url:'123',token:'233'} */ param: any; /** * 传入信息 */ message: any; }; export type pathItem = { params: string[]; /** * 连接函数 * @param data * @returns */ connection: (data: Omit<pathItemData, 'message'>) => any; /** * 接收信息函数 * @param data * @returns */ message: (data: pathItemData) => any; }; export default class CMockWSRouter { CMockConfig: CMockConfig; pathMap: { [key: string]: { [key: number]: pathItem; }; }; constructor(CMockConfig: CMockConfig); setPath: () => void; getUrl: (req: http.IncomingMessage) => { item: pathItem; param: { [key: string]: string; }; } | null; } export {};