boilerplate for grpc
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
syntax = "proto3";
|
||||
|
||||
service CharacterManager {
|
||||
rpc createCharacter(CreateCharacterRequest) returns (CreateCharacterResponse);
|
||||
rpc getCharacter(GetCharacterRequest) returns (GetCharacterResponse);
|
||||
rpc createCharacter(CreateCharacterRequest) returns (Character);
|
||||
rpc getCharacter(GetCharacterRequest) returns (Character);
|
||||
}
|
||||
|
||||
message Character {
|
||||
@@ -13,8 +13,4 @@ message Character {
|
||||
|
||||
message CreateCharacterRequest {}
|
||||
|
||||
message CreateCharacterResponse {}
|
||||
|
||||
message GetCharacterRequest {}
|
||||
|
||||
message GetCharacterResponse {}
|
||||
message GetCharacterRequest {}
|
||||
@@ -15,6 +15,7 @@ COPY vault .
|
||||
RUN npm install -g protoc
|
||||
RUN npm install -g protoc-gen-ts
|
||||
|
||||
RUN npm run build_protos
|
||||
RUN npm run build
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import js from "@eslint/js";
|
||||
import globals from "globals";
|
||||
import tseslint from "typescript-eslint";
|
||||
import { defineConfig } from "eslint/config";
|
||||
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"] },
|
||||
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], languageOptions: { globals: globals.node } },
|
||||
{
|
||||
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
|
||||
plugins: { js },
|
||||
extends: ['js/recommended'],
|
||||
},
|
||||
{
|
||||
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
|
||||
languageOptions: { globals: globals.node },
|
||||
},
|
||||
tseslint.configs.recommended,
|
||||
]);
|
||||
])
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import * as grpc from '@grpc/grpc-js'
|
||||
import { Server, ServerCredentials } from '@grpc/grpc-js'
|
||||
|
||||
import { initCharacterService } from './character_service'
|
||||
|
||||
const port = 8000;
|
||||
const port = 8000
|
||||
|
||||
const app = new grpc.Server()
|
||||
const app = new Server()
|
||||
|
||||
initCharacterService(app)
|
||||
|
||||
app.bindAsync("0.0.0.0:8000", grpc.ServerCredentials.createInsecure(), () => {
|
||||
console.log("Starting server at 0.0.0.0:8000")
|
||||
})
|
||||
app.bindAsync('0.0.0.0:8080', ServerCredentials.createInsecure(), () => {
|
||||
console.log('Starting server at 0.0.0.0:8080')
|
||||
})
|
||||
|
||||
@@ -1,10 +1,31 @@
|
||||
import * as grpc from '@grpc/grpc-js'
|
||||
import { Server, ServerUnaryCall, sendUnaryData } from '@grpc/grpc-js'
|
||||
|
||||
import { Character, GetCharacterRequest, GetCharacterResponse } from './proto/character'
|
||||
import {
|
||||
UnimplementedCharacterManagerService,
|
||||
Character,
|
||||
GetCharacterRequest,
|
||||
CreateCharacterRequest,
|
||||
} from './proto/character'
|
||||
|
||||
export function initCharacterService(server: grpc.Server) {
|
||||
export function initCharacterService(server: Server) {
|
||||
server.addService(UnimplementedCharacterManagerService.definition, {
|
||||
createCharacter: createCharacter_Call,
|
||||
getCharacter: getCharacter_Call,
|
||||
})
|
||||
}
|
||||
|
||||
function getCharacter(request: GetCharacterRequest): GetCharacterResponse {
|
||||
return new GetCharacterResponse()
|
||||
}
|
||||
function createCharacter_Call(call: ServerUnaryCall<CreateCharacterRequest, Character>, callback: sendUnaryData<Character>) {
|
||||
callback(null, createCharacter(call.request))
|
||||
}
|
||||
|
||||
function createCharacter(request: CreateCharacterRequest): Character {
|
||||
return new Character()
|
||||
}
|
||||
|
||||
function getCharacter_Call(call: ServerUnaryCall<GetCharacterRequest, Character>, callback: sendUnaryData<Character>) {
|
||||
callback(null, getCharacter(call.request))
|
||||
}
|
||||
|
||||
function getCharacter(request: GetCharacterRequest): Character {
|
||||
return new Character()
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@
|
||||
"outDir": "dist"
|
||||
},
|
||||
"lib": ["es2015"]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user