|
15 | 15 | *
|
16 | 16 | */
|
17 | 17 |
|
18 |
| -import { loadPackageDefinition, sendUnaryData, Server, ServerCredentials, ServerUnaryCall, UntypedServiceImplementation } from "@grpc/grpc-js"; |
| 18 | +import { loadPackageDefinition, sendUnaryData, Server, ServerCredentials, ServerOptions, ServerUnaryCall, UntypedServiceImplementation } from "@grpc/grpc-js"; |
19 | 19 | import { loadSync } from "@grpc/proto-loader";
|
20 | 20 | import { ProtoGrpcType } from "./generated/echo";
|
21 | 21 | import { EchoRequest__Output } from "./generated/grpc/testing/EchoRequest";
|
@@ -43,7 +43,7 @@ export class Backend {
|
43 | 43 | private receivedCallCount = 0;
|
44 | 44 | private callListeners: (() => void)[] = [];
|
45 | 45 | private port: number | null = null;
|
46 |
| - constructor() { |
| 46 | + constructor(private serverOptions?: ServerOptions) { |
47 | 47 | }
|
48 | 48 | Echo(call: ServerUnaryCall<EchoRequest__Output, EchoResponse>, callback: sendUnaryData<EchoResponse>) {
|
49 | 49 | // call.request.params is currently ignored
|
@@ -76,13 +76,12 @@ export class Backend {
|
76 | 76 | if (this.server) {
|
77 | 77 | throw new Error("Backend already running");
|
78 | 78 | }
|
79 |
| - this.server = new Server(); |
| 79 | + this.server = new Server(this.serverOptions); |
80 | 80 | this.server.addService(loadedProtos.grpc.testing.EchoTestService.service, this as unknown as UntypedServiceImplementation);
|
81 | 81 | const boundPort = this.port ?? 0;
|
82 | 82 | this.server.bindAsync(`localhost:${boundPort}`, ServerCredentials.createInsecure(), (error, port) => {
|
83 | 83 | if (!error) {
|
84 | 84 | this.port = port;
|
85 |
| - this.server!.start(); |
86 | 85 | }
|
87 | 86 | callback(error, port);
|
88 | 87 | })
|
|
0 commit comments