chore: 更新依赖并支持从 etcd 读取配置。

This commit is contained in:
Ivan Li 2021-10-28 22:07:29 +08:00
parent 6cf4d1b748
commit ece8ccf27a
7 changed files with 9468 additions and 14994 deletions

24306
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,61 +21,61 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs-lib/auth": "^0.2.1",
"@nestjs/bull": "^0.3.1",
"@nestjs/common": "^7.6.15",
"@nestjs/config": "^0.6.2",
"@nestjs/core": "^7.6.15",
"@nestjs/graphql": "^7.9.8",
"@nestjs/platform-express": "^7.6.15",
"@nestjs/typeorm": "^7.1.5",
"apollo-server-express": "^2.19.2",
"bcrypt": "^5.0.0",
"@fennec/configuration": "^0.0.1",
"@nestjs-lib/auth": "^0.2.3",
"@nestjs-lib/etcd3": "^0.0.1",
"@nestjs/common": "^8.1.1",
"@nestjs/config": "^1.0.3",
"@nestjs/core": "^8.1.1",
"@nestjs/graphql": "^9.1.1",
"@nestjs/platform-express": "^8.1.1",
"@nestjs/typeorm": "^8.0.2",
"apollo-server-express": "^3.4.0",
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"class-transformer": "^0.3.2",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"debug": "^4.3.1",
"graphql": "^15.5.0",
"graphql-tools": "^7.0.2",
"highlight.js": "^10.7.2",
"ioredis": "^4.25.0",
"js-yaml": "^4.0.0",
"marked": "^2.1.3",
"nestjs-etcd": "^0.2.0",
"nestjs-redis": "^1.2.8",
"observable-to-async-generator": "^1.0.1-rc",
"pg": "^8.5.1",
"debug": "^4.3.2",
"graphql": "^15.6.1",
"graphql-tools": "^8.2.0",
"highlight.js": "^11.3.1",
"ioredis": "^4.28.0",
"js-yaml": "^4.1.0",
"marked": "^3.0.7",
"nestjs-redis": "^1.3.3",
"observable-to-async-generator": "^1.0.2",
"pg": "^8.7.1",
"ramda": "^0.27.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.7",
"simple-git": "^2.35.0",
"typeorm": "^0.2.30"
"rxjs": "^7.4.0",
"simple-git": "^2.47.0",
"typeorm": "^0.2.38"
},
"devDependencies": {
"@nestjs/cli": "^7.5.7",
"@nestjs/schematics": "^7.3.1",
"@nestjs/testing": "^7.6.15",
"@types/express": "^4.17.8",
"@nestjs/cli": "^8.1.4",
"@nestjs/schematics": "^8.0.4",
"@nestjs/testing": "^8.1.1",
"@types/express": "^4.17.13",
"@types/highlight.js": "^10.1.0",
"@types/jest": "^26.0.22",
"@types/marked": "^2.0.3",
"@types/node": "^14.14.41",
"@types/jest": "^27.0.2",
"@types/marked": "^3.0.2",
"@types/node": "^16.11.2",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"apollo-server-testing": "^2.23.0",
"eslint": "^7.24.0",
"eslint-config-prettier": "7.2.0",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^26.6.3",
"prettier": "^2.1.2",
"supertest": "^6.0.0",
"ts-jest": "^26.5.5",
"ts-loader": "^8.1.0",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.2.4"
"eslint": "^8.0.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.3.1",
"prettier": "^2.4.1",
"supertest": "^6.1.6",
"ts-jest": "^27.0.7",
"ts-loader": "^9.2.6",
"ts-node": "^10.3.0",
"tsconfig-paths": "^3.11.0",
"typescript": "^4.4.4"
},
"jest": {
"moduleFileExtensions": [

View File

@ -6,12 +6,9 @@ import { AppController } from './app.controller';
import { AppResolver } from './app.resolver';
import { AppService } from './app.service';
import configuration from './commons/config/configuration';
import { RedisModule } from 'nestjs-redis';
import { ParseBodyMiddleware } from './commons/middleware/parse-body.middleware';
import { BullModule } from '@nestjs/bull';
import { PubSubModule } from './commons/pub-sub/pub-sub.module';
import { ArticlesModule } from './articles/articles.module';
import { EtcdModule } from 'nestjs-etcd';
import { EtcdModule } from '@nestjs-lib/etcd3';
import { CommonsModule } from './commons/commons.module';
import { TagsModule } from './tags/tags.module';
@ -19,9 +16,9 @@ import { TagsModule } from './tags/tags.module';
imports: [
ConfigModule.forRoot({
load: [configuration],
isGlobal: true,
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
type: 'postgres',
host: configService.get<string>('db.postgres.host'),
@ -35,7 +32,6 @@ import { TagsModule } from './tags/tags.module';
inject: [ConfigService],
}),
GraphQLModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
debug: configService.get<string>('env') !== 'prod',
playground: true,
@ -44,40 +40,7 @@ import { TagsModule } from './tags/tags.module';
}),
inject: [ConfigService],
}),
BullModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
redis: {
host: configService.get<string>('db.redis.host', 'localhost'),
port: configService.get<number>('db.redis.port', undefined),
password: configService.get<string>('db.redis.password', undefined),
},
}),
inject: [ConfigService],
}),
PubSubModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
redis: {
host: configService.get<string>('db.redis.host', 'localhost'),
port: configService.get<number>('db.redis.port', undefined),
password: configService.get<string>('db.redis.password', undefined),
},
}),
inject: [ConfigService],
}),
RedisModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
host: configService.get<string>('db.redis.host', 'localhost'),
port: configService.get<number>('db.redis.port', 6379),
password: configService.get<string>('db.redis.password', ''),
keyPrefix: configService.get<string>('db.redis.prefix', 'blog') + ':',
}),
inject: [ConfigService],
}),
EtcdModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
hosts: configService.get<string>('db.etcd.hosts', 'localhost:2379'),
}),

View File

@ -12,7 +12,7 @@ import { Article } from './entities/article.entity';
import { CreateArticleInput } from './dto/create-article.input';
import { UpdateArticleInput } from './dto/update-article.input';
import * as marked from 'marked';
import { getLanguage, highlight } from 'highlight.js';
import highlight from 'highlight.js';
import { AccountRole, Roles } from '@nestjs-lib/auth';
@Resolver(() => Article)
@ -65,8 +65,8 @@ export class ArticlesResolver {
smartypants: true,
langPrefix: 'hljs language-',
highlight: (code, language) => {
return highlight(code, {
language: getLanguage(language) ? language : 'plaintext',
return highlight.highlight(code, {
language: highlight.getLanguage(language) ? language : 'plaintext',
}).value;
},
});

View File

@ -1,9 +1,9 @@
import { readFileSync } from 'fs';
import * as yaml from 'js-yaml';
import { join } from 'path';
import { readConfiguration } from '@fennec/configuration';
export default () => {
return yaml.load(
readFileSync(join(__dirname, '../../../config.yml'), 'utf8'),
) as unknown;
return readConfiguration({
etcd: {
hosts: '192.168.31.2:2379',
},
});
};

View File

@ -16,5 +16,8 @@ async function bootstrap() {
);
app.useGlobalFilters(new HttpExceptionFilter());
await app.listen(configService.get<number>('http.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();

View File

@ -6,10 +6,12 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"lib": ["es2020"],
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
"incremental": true,
"skipLibCheck": true
}
}