Skip to main content

Fly 类

服务器主要逻辑如(报文解析,报文拼接,路由设置)都在此函数内实现:

 socket.on('data', (data) => {    const request = requestParser(JSON.stringify(data));    const response = ResponseInstance(responseSocket, request);    this.CROSEnabled ? response.enableCROS() : '';    this.router.handle(request, response);});

这里封装了一下,listen函数,方便调用:

start(port = 80): Promise<void> {    this.port = port;    this.server.listen(this.port);    const server = this.server;    return new Promise((resolve) => {      server.on('listening', resolve);    });  }