-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
30 lines (24 loc) · 1.16 KB
/
Copy pathserver.ts
File metadata and controls
30 lines (24 loc) · 1.16 KB
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
26
27
28
29
30
import { CallContext, ServerError, Status, createServer} from 'nice-grpc';
import {prometheusServerMiddleware} from 'nice-grpc-prometheus';
//import * as serverRegistry from './registry';
import { DeepPartial, GreetRequest, GreetResponse, GreetServiceDefinition, GreetServiceImplementation } from './compiled_proto/test'
import { ServerCredentials } from '@grpc/grpc-js';
// GreetService Impl object is defined with an `async` keyword, indiciating that it returns a -> PROMISE.
// Make sure the `greetings` method is using the -> promise-based approach instead of the callback approach.
const GreetServiceImpl: GreetServiceImplementation = {
async greetings(request: GreetRequest): Promise<DeepPartial<GreetResponse>> {
try {
const response: GreetResponse = {
Goodbye: 'bye!',
};
return response;
} catch (err) {
console.error(err);
throw new ServerError(Status.ABORTED, 'An error occurred');
}
},
};
const server = createServer()
server.use(prometheusServerMiddleware())
server.add(GreetServiceDefinition, GreetServiceImpl)
server.listen('127.0.0.1:3500', ServerCredentials.createInsecure())