feat: register service to api gateway.

This commit is contained in:
Ivan Li 2021-09-25 20:38:54 +08:00
parent 38dd05c4be
commit d5f49531e9
3 changed files with 45 additions and 1 deletions

38
package-lock.json generated
View File

@ -24,6 +24,7 @@
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"class-transformer": "^0.3.2", "class-transformer": "^0.3.2",
"class-validator": "^0.13.1", "class-validator": "^0.13.1",
"configuration": "file:../configuration",
"debug": "^4.3.1", "debug": "^4.3.1",
"graphql": "^15.5.0", "graphql": "^15.5.0",
"graphql-tools": "^8.1.0", "graphql-tools": "^8.1.0",
@ -74,6 +75,24 @@
"typescript": "^4.0.5" "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": { "node_modules/@angular-devkit/core": {
"version": "11.2.6", "version": "11.2.6",
"resolved": "https://npm.ivanli.cc/@angular-devkit%2fcore/-/core-11.2.6.tgz", "resolved": "https://npm.ivanli.cc/@angular-devkit%2fcore/-/core-11.2.6.tgz",
@ -6580,6 +6599,10 @@
"safe-buffer": "~5.1.0" "safe-buffer": "~5.1.0"
} }
}, },
"node_modules/configuration": {
"resolved": "../configuration",
"link": true
},
"node_modules/consola": { "node_modules/consola": {
"version": "2.15.3", "version": "2.15.3",
"resolved": "https://npm.ivanli.cc/consola/-/consola-2.15.3.tgz", "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": { "consola": {
"version": "2.15.3", "version": "2.15.3",
"resolved": "https://npm.ivanli.cc/consola/-/consola-2.15.3.tgz", "resolved": "https://npm.ivanli.cc/consola/-/consola-2.15.3.tgz",

View File

@ -37,6 +37,7 @@
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"class-transformer": "^0.3.2", "class-transformer": "^0.3.2",
"class-validator": "^0.13.1", "class-validator": "^0.13.1",
"configuration": "file:../configuration",
"debug": "^4.3.1", "debug": "^4.3.1",
"graphql": "^15.5.0", "graphql": "^15.5.0",
"graphql-tools": "^8.1.0", "graphql-tools": "^8.1.0",

View File

@ -5,6 +5,7 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
import { HttpExceptionFilter } from './commons/filters/all.exception-filter'; import { HttpExceptionFilter } from './commons/filters/all.exception-filter';
import { SanitizePipe } from './commons/pipes/sanitize.pipe'; import { SanitizePipe } from './commons/pipes/sanitize.pipe';
import { ServiceRegister } from 'configuration';
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule, { bodyParser: false }); const app = await NestFactory.create(AppModule, { bodyParser: false });
@ -17,6 +18,10 @@ async function bootstrap() {
); );
const httpExceptionFilterLogger = await app.resolve(PinoLogger); const httpExceptionFilterLogger = await app.resolve(PinoLogger);
app.useGlobalFilters(new HttpExceptionFilter(httpExceptionFilterLogger)); app.useGlobalFilters(new HttpExceptionFilter(httpExceptionFilterLogger));
await app.listen(configService.get<number>('http.port')); const server = await app.listen(configService.get<number>('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(); bootstrap();