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

View File

@ -6,12 +6,9 @@ import { AppController } from './app.controller';
import { AppResolver } from './app.resolver'; import { AppResolver } from './app.resolver';
import { AppService } from './app.service'; import { AppService } from './app.service';
import configuration from './commons/config/configuration'; import configuration from './commons/config/configuration';
import { RedisModule } from 'nestjs-redis';
import { ParseBodyMiddleware } from './commons/middleware/parse-body.middleware'; 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 { ArticlesModule } from './articles/articles.module';
import { EtcdModule } from 'nestjs-etcd'; import { EtcdModule } from '@nestjs-lib/etcd3';
import { CommonsModule } from './commons/commons.module'; import { CommonsModule } from './commons/commons.module';
import { TagsModule } from './tags/tags.module'; import { TagsModule } from './tags/tags.module';
@ -19,9 +16,9 @@ import { TagsModule } from './tags/tags.module';
imports: [ imports: [
ConfigModule.forRoot({ ConfigModule.forRoot({
load: [configuration], load: [configuration],
isGlobal: true,
}), }),
TypeOrmModule.forRootAsync({ TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({ useFactory: (configService: ConfigService) => ({
type: 'postgres', type: 'postgres',
host: configService.get<string>('db.postgres.host'), host: configService.get<string>('db.postgres.host'),
@ -35,7 +32,6 @@ import { TagsModule } from './tags/tags.module';
inject: [ConfigService], inject: [ConfigService],
}), }),
GraphQLModule.forRootAsync({ GraphQLModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({ useFactory: (configService: ConfigService) => ({
debug: configService.get<string>('env') !== 'prod', debug: configService.get<string>('env') !== 'prod',
playground: true, playground: true,
@ -44,40 +40,7 @@ import { TagsModule } from './tags/tags.module';
}), }),
inject: [ConfigService], 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({ EtcdModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({ useFactory: (configService: ConfigService) => ({
hosts: configService.get<string>('db.etcd.hosts', 'localhost:2379'), 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 { CreateArticleInput } from './dto/create-article.input';
import { UpdateArticleInput } from './dto/update-article.input'; import { UpdateArticleInput } from './dto/update-article.input';
import * as marked from 'marked'; import * as marked from 'marked';
import { getLanguage, highlight } from 'highlight.js'; import highlight from 'highlight.js';
import { AccountRole, Roles } from '@nestjs-lib/auth'; import { AccountRole, Roles } from '@nestjs-lib/auth';
@Resolver(() => Article) @Resolver(() => Article)
@ -65,8 +65,8 @@ export class ArticlesResolver {
smartypants: true, smartypants: true,
langPrefix: 'hljs language-', langPrefix: 'hljs language-',
highlight: (code, language) => { highlight: (code, language) => {
return highlight(code, { return highlight.highlight(code, {
language: getLanguage(language) ? language : 'plaintext', language: highlight.getLanguage(language) ? language : 'plaintext',
}).value; }).value;
}, },
}); });

View File

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

View File

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

View File

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