Compare commits
2 Commits
28a991c7d4
...
aa4c44840b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa4c44840b | ||
|
|
882e8cf72a |
10
vault/package-lock.json
generated
10
vault/package-lock.json
generated
@@ -13,6 +13,7 @@
|
|||||||
"@grpc/proto-loader": "^0.7.15",
|
"@grpc/proto-loader": "^0.7.15",
|
||||||
"@grpc/reflection": "^1.0.4",
|
"@grpc/reflection": "^1.0.4",
|
||||||
"@protobuf-ts/protoc": "^2.11.0",
|
"@protobuf-ts/protoc": "^2.11.0",
|
||||||
|
"commander": "^14.0.0",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"google-protobuf": "^3.21.4",
|
"google-protobuf": "^3.21.4",
|
||||||
"mongodb": "^6.17.0"
|
"mongodb": "^6.17.0"
|
||||||
@@ -1329,6 +1330,15 @@
|
|||||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/commander": {
|
||||||
|
"version": "14.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/commander/-/commander-14.0.0.tgz",
|
||||||
|
"integrity": "sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/concat-map": {
|
"node_modules/concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
"@grpc/proto-loader": "^0.7.15",
|
"@grpc/proto-loader": "^0.7.15",
|
||||||
"@grpc/reflection": "^1.0.4",
|
"@grpc/reflection": "^1.0.4",
|
||||||
"@protobuf-ts/protoc": "^2.11.0",
|
"@protobuf-ts/protoc": "^2.11.0",
|
||||||
|
"commander": "^14.0.0",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"google-protobuf": "^3.21.4",
|
"google-protobuf": "^3.21.4",
|
||||||
"mongodb": "^6.17.0"
|
"mongodb": "^6.17.0"
|
||||||
|
|||||||
@@ -3,17 +3,23 @@ import { MongoClient } from 'mongodb'
|
|||||||
|
|
||||||
import { CharacterService } from './character_service'
|
import { CharacterService } from './character_service'
|
||||||
import { DatabaseService } from './database'
|
import { DatabaseService } from './database'
|
||||||
|
import { Flags } from './flags'
|
||||||
|
|
||||||
|
const flags = new Flags()
|
||||||
|
|
||||||
|
const port = flags.getPort()
|
||||||
|
|
||||||
const port = 8080
|
|
||||||
const address = `0.0.0.0:${port}`
|
const address = `0.0.0.0:${port}`
|
||||||
|
|
||||||
|
const databaseService = new DatabaseService(
|
||||||
|
flags.getMongoDbAddress(),
|
||||||
|
flags.getMongoDbName(),
|
||||||
|
)
|
||||||
|
|
||||||
|
const characterService = new CharacterService(databaseService)
|
||||||
const app = new Server()
|
const app = new Server()
|
||||||
|
|
||||||
const databaseService = new DatabaseService('mongodb://rushvault:rushvault@mongo:27017/', 'rush-vault')
|
|
||||||
const characterService = new CharacterService(databaseService)
|
|
||||||
|
|
||||||
characterService.addToServer(app)
|
|
||||||
|
|
||||||
app.bindAsync(address, ServerCredentials.createInsecure(), () => {
|
app.bindAsync(address, ServerCredentials.createInsecure(), () => {
|
||||||
|
characterService.addToServer(app)
|
||||||
console.log(`Starting server at ${address}`)
|
console.log(`Starting server at ${address}`)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ export class CharacterService {
|
|||||||
characterManager: ICharacterManager
|
characterManager: ICharacterManager
|
||||||
databaseService: DatabaseService
|
databaseService: DatabaseService
|
||||||
|
|
||||||
// mongoClient: MongoClient
|
|
||||||
// db: Db
|
|
||||||
// characterCollection: Collection
|
|
||||||
|
|
||||||
constructor(databaseService: DatabaseService) {
|
constructor(databaseService: DatabaseService) {
|
||||||
this.reflectionService = new ReflectionService(
|
this.reflectionService = new ReflectionService(
|
||||||
loadSync('./src/proto/character.proto'),
|
loadSync('./src/proto/character.proto'),
|
||||||
@@ -35,10 +31,6 @@ export class CharacterService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.databaseService = databaseService
|
this.databaseService = databaseService
|
||||||
|
|
||||||
// this.mongoClient = mongoClient
|
|
||||||
// this.db = this.mongoClient.db(dbName)
|
|
||||||
// this.characterCollection = this.db.collection('Characters')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addToServer(server: Server) {
|
addToServer(server: Server) {
|
||||||
@@ -51,17 +43,9 @@ export class CharacterService {
|
|||||||
call: ServerUnaryCall<CreateCharacterRequest, Character>,
|
call: ServerUnaryCall<CreateCharacterRequest, Character>,
|
||||||
callback: sendUnaryData<Character>,
|
callback: sendUnaryData<Character>,
|
||||||
) {
|
) {
|
||||||
|
let newCharacter = await this.databaseService.insertCharacter(
|
||||||
let newCharacter = await this.databaseService.insertCharacter(call.request.characterData)
|
call.request.characterData,
|
||||||
|
)
|
||||||
// this.characterCollection
|
|
||||||
// .insertOne(call.request.characterData)
|
|
||||||
// .then((insertResult) => {
|
|
||||||
// console.log(insertResult)
|
|
||||||
// return this.characterCollection.findOne({
|
|
||||||
// _id: insertResult.insertedId,
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
console.log(newCharacter)
|
console.log(newCharacter)
|
||||||
|
|
||||||
|
|||||||
32
vault/src/flags.ts
Normal file
32
vault/src/flags.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { Command } from 'commander'
|
||||||
|
|
||||||
|
export class Flags {
|
||||||
|
private readonly program = new Command()
|
||||||
|
.option('-p, --port <number>', 'server port number', '8080')
|
||||||
|
.option(
|
||||||
|
'--mongoPath <string>',
|
||||||
|
'mongo db path',
|
||||||
|
'mongodb://rushvault:rushvault@mongo:27017/',
|
||||||
|
)
|
||||||
|
.option(
|
||||||
|
'--mongoDb <string>',
|
||||||
|
'name of the databse to store collections',
|
||||||
|
'rush-vault',
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.program.parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
getPort(): number {
|
||||||
|
return this.program.opts().port
|
||||||
|
}
|
||||||
|
|
||||||
|
getMongoDbAddress(): string {
|
||||||
|
return this.program.opts().mongoPath
|
||||||
|
}
|
||||||
|
|
||||||
|
getMongoDbName(): string {
|
||||||
|
return this.program.opts().mongoDb
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user