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

Commit

Permalink
fix: try all cors
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Nov 10, 2021
1 parent 244ae0e commit fdce33a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 35 deletions.
8 changes: 3 additions & 5 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module, Logger } from '@nestjs/common'
import { Module } from '@nestjs/common'
import { APP_PIPE, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core'
import { GraphQLValidationPipe } from './shared/pipes/GraphQLValidation.pipe'
import { RolesGuard } from './shared/guard/roles.guard'
Expand All @@ -21,13 +21,14 @@ import { MottosModule } from './mottos/mottos.module'
import { CoversModule } from './covers/covers.module'
import { GlobalSettingModule } from './global-setting/global-setting.module'
import { PostStatisticsModule } from './post-statistics/post-statistics.module'
import { WinstonLogModule } from './shared/log/log.module'
import { LoggerModule } from './shared/logger/logger.module'

@Module({
imports: [
ConfigModule,
GraphqlModule,
DataBaseModule,
LoggerModule,
AuthModule,
UsersModule,
AnnouncementsModule,
Expand All @@ -43,7 +44,6 @@ import { WinstonLogModule } from './shared/log/log.module'
CoversModule,
GlobalSettingModule,
PostStatisticsModule,
WinstonLogModule,
],

providers: [
Expand All @@ -61,8 +61,6 @@ import { WinstonLogModule } from './shared/log/log.module'
provide: APP_INTERCEPTOR,
useClass: DelayInterceptor,
},

Logger,
],
})
export class AppModule {}
2 changes: 0 additions & 2 deletions src/graphql/graphqls.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core'
import { ConfigModule } from '../config/config.module'
import { ConfigService } from '../config/config.service'
import { SCHEMA_GQL_FILE_NAME } from '../shared/constants'
import { configCORS } from '../shared/utils'

@Module({
imports: [
Expand Down Expand Up @@ -36,7 +35,6 @@ import { configCORS } from '../shared/utils'
plugins: [
!configService.isEnvProduction && ApolloServerPluginLandingPageLocalDefault(),
].filter(Boolean),
cors: configCORS(configService.isEnvProduction),
}),

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

const bootstrap = async () => {
const app = await NestFactory.create<NestExpressApplication>(AppModule)
const app = await NestFactory.create<NestExpressApplication>(AppModule, { logger: false })
app.setGlobalPrefix('beg')
app.enableCors({})
configMiddlewares(app)
configLogger(app)
await app.listen(process.env.port || 3002)
Expand Down
26 changes: 0 additions & 26 deletions src/shared/log/log.module.ts

This file was deleted.

File renamed without changes.
54 changes: 54 additions & 0 deletions src/shared/logger/logger.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Module } from '@nestjs/common'
import { WinstonModule, utilities } from 'nest-winston'
import * as winston from 'winston'
import { DateTime } from 'luxon'

const {
errors,
combine,
json,
timestamp,
ms,
prettyPrint,
colorize,
label,
splat,
} = winston.format

@Module({
imports: [
WinstonModule.forRoot({
format: combine(
colorize(),
errors(),
json(),
timestamp({ format: 'HH:mm:ss YY/MM/DD' }),
ms(),
prettyPrint(),
label({
label: '[UPLOADER SERVICE] ',
}),
splat(),
),
transports: [
new winston.transports.File({
level: 'error',
filename: `error-${DateTime.now().toISODate()}.log`,
dirname: 'logs',
maxsize: 5000000,
}),
new winston.transports.Console({
level: 'debug',
format: combine(utilities.format.nestLike()),
}),

new winston.transports.File({
filename: `application-${DateTime.now().toISODate()}.log`,
dirname: 'logs',
maxsize: 5000000,
}),
],
}),
],
})
export class LoggerModule {}

0 comments on commit fdce33a

Please sign in to comment.