[add] first

This commit is contained in:
2022-04-29 15:25:10 +08:00
commit da8024fc30
87 changed files with 16892 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import { TsrpcError } from "tsrpc-proto";
import { ApiCallHttp } from '../../../src/server/http/HttpCall';
import { ReqTest } from "../../proto/PtlTest";
import { ResTest } from '../../proto/a/b/c/PtlTest';
export async function ApiTest(call: ApiCallHttp<ReqTest, ResTest>) {
if (Math.random() > 0.75) {
call.succ({
reply: 'Hello, ' + call.req.name
})
}
else if (Math.random() > 0.5) {
call.error('What the fuck??', { msg: '哈哈哈哈' })
}
else if (Math.random() > 0.25) {
throw new Error('这应该是InternalERROR')
}
else {
throw new TsrpcError('返回到前台的错误', 'ErrInfo');
}
}

View File

@@ -0,0 +1,5 @@
export async function ApiTest(call: any) {
call.succ({
reply: 'Api Test1 Succ'
})
}

22
test/try/server/http.ts Normal file
View File

@@ -0,0 +1,22 @@
import { serviceProto } from '../proto/serviceProto';
import * as path from "path";
import { TsrpcServer } from '../../index';
let server = new TsrpcServer({
proto: serviceProto
});
server.dataFlow.push((data, conn) => {
let httpReq = conn.options.httpReq;
if (httpReq.method === 'GET') {
conn.logger.log('url', httpReq.url);
conn.logger.log('host', httpReq.headers.host);
conn.options.httpRes.end('Hello~~~');
return false;
}
return true;
})
server.autoImplementApi(path.resolve(__dirname, 'api'));
server.start();

18
test/try/server/ws.ts Normal file
View File

@@ -0,0 +1,18 @@
import { serviceProto, ServiceType } from '../proto/serviceProto';
import * as path from "path";
import { TsrpcServerWs } from '../../index';
let server = new TsrpcServerWs<ServiceType>({
proto: serviceProto
});
server.start();
server.autoImplementApi(path.resolve(__dirname, 'api'));
server.listenMsg('Chat', v => {
v.conn.sendMsg('Chat', {
channel: v.msg.channel,
userName: 'SYSTEM',
content: '收到',
time: Date.now()
})
})