Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
feat: migrate to nest8
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Nov 10, 2021
2 parents 44fa9dd + 2fef6d5 commit b749544
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 973 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.17.1](https://github.com/Yancey-Blog/blog-be-next/compare/v1.17.0...v1.17.1) (2021-11-10)


### Bug Fixes

* fix cors node_env ([2536825](https://github.com/Yancey-Blog/blog-be-next/commit/2536825ec607129bcb321eadf7601e1eed950ece))

## [1.17.0](https://github.com/Yancey-Blog/blog-be-next/compare/v1.16.0...v1.17.0) (2021-11-09)


### Features

* add globalFix ([90eed1a](https://github.com/Yancey-Blog/blog-be-next/commit/90eed1addeb6e4c032b36396417547963d61a17a))

## [1.16.0](https://github.com/Yancey-Blog/blog-be-next/compare/v1.15.4...v1.16.0) (2021-11-09)


### Features

* remove uploader service ([96af669](https://github.com/Yancey-Blog/blog-be-next/commit/96af6694d63c027421688a13347b495577288eea))

### [1.15.4](https://github.com/Yancey-Blog/blog-be-next/compare/v1.15.3...v1.15.4) (2021-11-08)


Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ BANDWAGON_SECRET_KEY=<YOUR_BANDWAGON_SECRET_KEY>
BANDWAGON_SERVER_ID=<YOUR_BANDWAGON_SERVER_ID>
IP_STACK_ACCESS_KEY=<YOUR_IP_STACK_ACCESS_KEY>
GOOGLE_RECAPTCHA_KEY=<YOUR_GOOGLE_RECAPTCHA_KEY>
AZURE_STORAGE_CONNECTION_STRING=<YOUR_AZURE_STORAGE_CONNECTION_STRING>
JWT_SECRET_KEY=<YOUR_JWT_SECRET_KEY>
JWT_EXPIRES_TIME=<YOUR_JWT_EXPIRES_TIME>
# Only works on the development environment.
Expand Down
1 change: 0 additions & 1 deletion env/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ IP_STACK_ACCESS_KEY=<YOUR_IP_STACK_ACCESS_KEY>
JWT_SECRET_KEY=<YOUR_JWT_SECRET_KEY>
JWT_EXPIRES_TIME=<YOUR_JWT_EXPIRES_TIME>
GOOGLE_RECAPTCHA_KEY=<YOUR_GOOGLE_RECAPTCHA_KEY>
AZURE_STORAGE_CONNECTION_STRING=<YOUR_AZURE_STORAGE_CONNECTION_STRING>
NEED_SIMULATE_NETWORK_THROTTLE=<BOOLEAN>
44 changes: 18 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blog-be-next",
"version": "1.15.4",
"version": "1.17.1",
"description": "The backend platform for Yancey blog.",
"repository": "git@github.com:Yancey-Blog/blog-be-next.git",
"author": "YanceyOfficial <yanceyofficial@gmail.com>",
Expand Down Expand Up @@ -28,61 +28,54 @@
"codecov": "node_modules/.bin/codecov -t 7b33b616-c7c6-465f-a858-91ca93071f98"
},
"dependencies": {
"@alicloud/pop-core": "^1.7.10",
"@apollo/gateway": "^0.41.0",
"@apollo/gateway": "^0.43.1",
"@azure/storage-blob": "^12.8.0",
"@nestjs/axios": "^0.0.1",
"@nestjs/axios": "^0.0.3",
"@nestjs/common": "^8.0.6",
"@nestjs/config": "^1.0.1",
"@nestjs/core": "^8.0.6",
"@nestjs/graphql": "^9.0.4",
"@nestjs/graphql": "^9.1.1",
"@nestjs/jwt": "^8.0.0",
"@nestjs/mongoose": "^8.0.1",
"@nestjs/mongoose": "^9.0.1",
"@nestjs/passport": "^8.0.1",
"@nestjs/platform-express": "^8.0.6",
"apollo-server-core": "^3.3.0",
"apollo-server-express": "^3.3.0",
"apollo-server-core": "^3.5.0",
"apollo-server-express": "^3.5.0",
"bcrypt": "^5.0.1",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"dotenv": "^10.0.0",
"express-rate-limit": "^5.3.0",
"graphql": "^15.5.3",
"graphql-upload": "^12.0.0",
"graphql": "^15.7.2",
"helmet": "^4.6.0",
"joi": "^17.4.2",
"luxon": "^2.0.2",
"mongoose": "^6.0.6",
"morgan": "^1.10.0",
"nest-winston": "^1.6.0",
"passport": "^0.4.1",
"passport": "^0.5.0",
"passport-jwt": "^4.0.0",
"qrcode": "^1.4.4",
"reflect-metadata": "^0.1.13",
"request-ip": "^2.1.3",
"rxjs": "^7.3.0",
"serve-favicon": "^2.5.0",
"sharp": "^0.29.1",
"speakeasy": "^2.0.0",
"ts-morph": "^12.0.0",
"ua-parser-js": "^0.7.28",
"ts-morph": "^12.2.0",
"ua-parser-js": "^1.0.2",
"uuid": "^8.3.2",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5",
"yancey-js-util": "^3.0.0"
},
"devDependencies": {
"@commitlint/cli": "^13.1.0",
"@commitlint/cli": "^14.1.0",
"@commitlint/config-conventional": "^14.1.0",
"@nestjs/cli": "^8.1.1",
"@nestjs/schematics": "^8.0.3",
"@nestjs/testing": "^8.0.6",
"@types/bcrypt": "^5.0.0",
"@types/csurf": "^1.11.2",
"@types/express-rate-limit": "^5.1.3",
"@types/graphql-upload": "^8.0.7",
"@types/jest": "^27.0.1",
"@types/luxon": "^2.0.5",
"@types/luxon": "^2.0.7",
"@types/morgan": "^1.9.3",
"@types/multer": "^1.4.7",
"@types/node": "^16.9.2",
Expand All @@ -91,20 +84,19 @@
"@types/ramda": "^0.27.44",
"@types/request-ip": "^0.0.37",
"@types/serve-favicon": "^2.5.3",
"@types/sharp": "^0.29.2",
"@types/speakeasy": "^2.0.6",
"@types/supertest": "^2.0.11",
"@types/ua-parser-js": "^0.7.36",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.31.1",
"@typescript-eslint/eslint-plugin": "^5.3.1",
"@typescript-eslint/parser": "^5.3.1",
"codecov": "^3.8.2",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.32.0",
"eslint": "^8.2.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.4.2",
"eslint-plugin-jest": "^25.2.4",
"eslint-plugin-nestjs": "^1.2.3",
"husky": "^4.3.8",
"jest": "^27.2.0",
Expand Down
2 changes: 0 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ConfigModule } from './config/config.module'
import { DataBaseModule } from './database/database.module'
import { GraphqlModule } from './graphql/graphqls.module'
import { AuthModule } from './auth/auth.module'
import { UploaderModule } from './uploader/uploader.module'
import { UsersModule } from './users/users.module'
import { AnnouncementsModule } from './announcements/announcements.module'
import { OpenSourcesModule } from './open-sources/open-sources.module'
Expand Down Expand Up @@ -45,7 +44,6 @@ import { WinstonLogModule } from './shared/log/log.module'
GlobalSettingModule,
PostStatisticsModule,
WinstonLogModule,
UploaderModule,
],

providers: [
Expand Down
5 changes: 0 additions & 5 deletions src/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ export class ConfigService {
return this.get('GOOGLE_RECAPTCHA_KEY')
}

public getAzureStorageConnectionString(): string {
return this.get('AZURE_STORAGE_CONNECTION_STRING')
}

private validateEnvFile(envConfig: EnvConfig): EnvConfig {
const envVarsSchema: ObjectSchema = Joi.object({
NODE_ENV: Joi.string()
Expand All @@ -93,7 +89,6 @@ export class ConfigService {
JWT_SECRET_KEY: Joi.string().required(),
JWT_EXPIRES_TIME: Joi.number().required(),
GOOGLE_RECAPTCHA_KEY: Joi.string().required(),
AZURE_STORAGE_CONNECTION_STRING: Joi.string().required(),
NEED_SIMULATE_NETWORK_THROTTLE: Joi.boolean().optional(),
})

Expand Down
3 changes: 2 additions & 1 deletion src/graphql/graphqls.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { configCORS } from '../shared/utils'
playground: false,
introspection: !configService.isEnvProduction,
installSubscriptionHandlers: true,
useGlobalPrefix: true,
typePaths: ['./**/*.gql'],
autoSchemaFile: SCHEMA_GQL_FILE_NAME,
context: ({ req }) => ({ req }),
Expand All @@ -35,7 +36,7 @@ import { configCORS } from '../shared/utils'
plugins: [
!configService.isEnvProduction && ApolloServerPluginLandingPageLocalDefault(),
].filter(Boolean),
cors: configCORS(),
cors: configCORS(configService.isEnvProduction),
}),

inject: [ConfigService],
Expand Down
10 changes: 4 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { NestFactory } from '@nestjs/core'
import { NestExpressApplication } from '@nestjs/platform-express'
import { configLog } from './shared/log/log.config'
import { configLogger } from './shared/log/log.config'
import { configMiddlewares } from './shared/middlewares/middleware.config'
import { AppModule } from './app.module'

const bootstrap = async () => {
const app = await NestFactory.create<NestExpressApplication>(AppModule)

app.setGlobalPrefix('beg')
configMiddlewares(app)
configLog(app)

// eslint-disable-next-line no-console
await app.listen(process.env.port || 3002, () => console.log('Server is listening on port 3002.'))
configLogger(app)
await app.listen(process.env.port || 3002)
}

bootstrap()
4 changes: 0 additions & 4 deletions src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ export const GOOGLE_RECAPTCHA_URL = 'https://www.google.com/recaptcha/api/siteve

export const IP_STACK_URL = 'http://api.ipstack.com/'

export const AZURE_STORAGE_URL = 'https://edge.yancey.app'

export const AZURE_STORAGE_CONTAINER_NAME = 'beg'

export const SCHEMA_GQL_FILE_NAME = 'schema.gql'

export const TOTP_ENCODE = 'base32'
Expand Down
23 changes: 0 additions & 23 deletions src/shared/filters/http-exception.filter.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/shared/guard/HTTPAuth.guard.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/shared/log/log.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INestApplication } from '@nestjs/common'
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston'
import { GraphQLExceptionFilter } from '../filters/graqhql-exception.filter'

export const configLog = (app: INestApplication) => {
export const configLogger = (app: INestApplication) => {
const nestWinston = app.get(WINSTON_MODULE_NEST_PROVIDER)
app.useLogger(nestWinston)
app.useGlobalFilters(new GraphQLExceptionFilter(nestWinston.logger))
Expand Down
12 changes: 1 addition & 11 deletions src/shared/log/log.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Module } from '@nestjs/common'
import { WinstonModule } from 'nest-winston'
import * as winston from 'winston'
import DailyRotateFile from 'winston-daily-rotate-file'

const { format } = winston

Expand All @@ -20,16 +19,7 @@ const { format } = winston
format.splat(),
format.printf((info) => `${info.timestamp} ${info.level}: [${info.label}] ${info.message}`),
),
transports: [
new winston.transports.Console(),
new DailyRotateFile({
filename: 'logs/application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d',
}),
],
transports: [new winston.transports.Console()],
}),
],
})
Expand Down
8 changes: 0 additions & 8 deletions src/shared/middlewares/middleware.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import path from 'path'
import serveFavicon from 'serve-favicon'
import morgan from 'morgan'
import helmet from 'helmet'
import rateLimit from 'express-rate-limit'
// import { configCORS } from '../utils'

export const configMiddlewares = (app: INestApplication) => {
app.use(serveFavicon(path.join(process.cwd(), 'public/favicon.ico')))
Expand All @@ -13,10 +11,4 @@ export const configMiddlewares = (app: INestApplication) => {
helmet({ contentSecurityPolicy: process.env.NODE_ENV === 'production' ? undefined : false }),
)
app.enableCors({})
app.use(
rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
}),
)
}
20 changes: 8 additions & 12 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ export const decodeJWT = (token: string) => jwt.decode(token.slice(7)) as Payloa

export const encryptPassword = (password: string) => bcrypt.hashSync(password, 10)

export const configCORS = () => {
const isEnvProduction = process.env.NODE_ENV === 'production'

return {
origin: isEnvProduction ? CORS_ORIGINS_PRODUCTION : CORS_ORIGINS_UN_PRODUCTION,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
preflightContinue: false,
optionsSuccessStatus: 204,
allowedHeaders: '*',
}
}
export const configCORS = (isEnvProduction: boolean) => ({
origin: isEnvProduction ? CORS_ORIGINS_PRODUCTION : CORS_ORIGINS_UN_PRODUCTION,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
preflightContinue: false,
optionsSuccessStatus: 204,
allowedHeaders: '*',
})
9 changes: 0 additions & 9 deletions src/uploader/uploader.module.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/uploader/uploader.resolver.ts

This file was deleted.

Loading

0 comments on commit b749544

Please sign in to comment.