diff --git a/package-lock.json b/package-lock.json index 8b552a6..1bc83e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "body-parser": "^1.19.0", "class-transformer": "^0.3.2", "class-validator": "^0.13.1", + "configuration": "file:../configuration", "debug": "^4.3.1", "graphql": "^15.5.0", "graphql-tools": "^8.1.0", @@ -74,6 +75,24 @@ "typescript": "^4.0.5" } }, + "../configuration": { + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "debug": "^4.3.2", + "etcd3": "^1.1.0", + "js-yaml": "^4.1.0" + }, + "devDependencies": { + "@tsconfig/node14": "^1.0.1", + "@types/debug": "^4.1.7", + "@types/js-yaml": "^4.0.3", + "@types/node": "^14.17.17", + "rimraf": "^3.0.2", + "ts-node": "^10.2.1", + "typescript": "^4.4.3" + } + }, "node_modules/@angular-devkit/core": { "version": "11.2.6", "resolved": "https://npm.ivanli.cc/@angular-devkit%2fcore/-/core-11.2.6.tgz", @@ -6580,6 +6599,10 @@ "safe-buffer": "~5.1.0" } }, + "node_modules/configuration": { + "resolved": "../configuration", + "link": true + }, "node_modules/consola": { "version": "2.15.3", "resolved": "https://npm.ivanli.cc/consola/-/consola-2.15.3.tgz", @@ -23152,6 +23175,21 @@ } } }, + "configuration": { + "version": "file:../configuration", + "requires": { + "@tsconfig/node14": "^1.0.1", + "@types/debug": "^4.1.7", + "@types/js-yaml": "^4.0.3", + "@types/node": "^14.17.17", + "debug": "^4.3.2", + "etcd3": "^1.1.0", + "js-yaml": "^4.1.0", + "rimraf": "^3.0.2", + "ts-node": "^10.2.1", + "typescript": "^4.4.3" + } + }, "consola": { "version": "2.15.3", "resolved": "https://npm.ivanli.cc/consola/-/consola-2.15.3.tgz", diff --git a/package.json b/package.json index 6b0cdd5..0c297c5 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "body-parser": "^1.19.0", "class-transformer": "^0.3.2", "class-validator": "^0.13.1", + "configuration": "file:../configuration", "debug": "^4.3.1", "graphql": "^15.5.0", "graphql-tools": "^8.1.0", diff --git a/src/main.ts b/src/main.ts index 1b9d634..74041a8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,6 +5,7 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { HttpExceptionFilter } from './commons/filters/all.exception-filter'; import { SanitizePipe } from './commons/pipes/sanitize.pipe'; +import { ServiceRegister } from 'configuration'; async function bootstrap() { const app = await NestFactory.create(AppModule, { bodyParser: false }); @@ -17,6 +18,10 @@ async function bootstrap() { ); const httpExceptionFilterLogger = await app.resolve(PinoLogger); app.useGlobalFilters(new HttpExceptionFilter(httpExceptionFilterLogger)); - await app.listen(configService.get('http.port')); + const server = await app.listen(configService.get('http.port', 0)); + const port = server.address().port; + const register = new ServiceRegister({ etcd: { hosts: 'http://rpi:2379' } }); + register.register('fennec/api', `http://localhost:${port}`); + register.register('api.fennec', `http://localhost:${port}`); } bootstrap();