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

Commit

Permalink
feat: update middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Sep 14, 2021
1 parent 8b12cf9 commit 98184dc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 493 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
"@nestjs/mongoose": "^7.2.2",
"@nestjs/passport": "^7.1.5",
"@nestjs/platform-express": "^7.6.18",
"ali-oss": "^6.15.2",
"apollo-server-express": "^2.25.0",
"axios": "^0.21.1",
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"dotenv": "^10.0.0",
Expand Down Expand Up @@ -77,7 +75,6 @@
"@nestjs/cli": "^7.6.0",
"@nestjs/schematics": "^7.3.0",
"@nestjs/testing": "^7.6.18",
"@types/ali-oss": "^6.0.7",
"@types/bcrypt": "^5.0.0",
"@types/csurf": "^1.11.0",
"@types/express-rate-limit": "^5.1.3",
Expand Down
34 changes: 13 additions & 21 deletions src/shared/middlewares/middleware.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { INestApplication } from '@nestjs/common'
import path from 'path'
import serveFavicon from 'serve-favicon'
import bodyParser from 'body-parser'
import morgan from 'morgan'
import helmet from 'helmet'
import rateLimit from 'express-rate-limit'
Expand All @@ -10,31 +9,24 @@ import { CORS_ORIGINS } from '../constants'
export const configMiddlewares = (app: INestApplication) => {
const isEnvProduction = process.env.NODE_ENV === 'production'

console.log(isEnvProduction)

app.use(serveFavicon(path.join(process.cwd(), 'public/favicon.ico')))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(morgan('combined'))
app.use(
helmet({ contentSecurityPolicy: process.env.NODE_ENV === 'production' ? undefined : false }),
)
// app.enableCors(
// isEnvProduction
// ? {
// origin: CORS_ORIGINS,
// methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
// credentials: true,
// preflightContinue: true,
// optionsSuccessStatus: 204,
// }
// : {},
// )
app.enableCors({
origin: '*',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
preflightContinue: true,
optionsSuccessStatus: 204,
})
app.enableCors(
isEnvProduction
? {
origin: CORS_ORIGINS,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
preflightContinue: true,
optionsSuccessStatus: 204,
}
: {},
)
app.use(
rateLimit({
windowMs: 15 * 60 * 1000,
Expand Down
1 change: 0 additions & 1 deletion src/uploaders/uploaders.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common'
import { FileUpload } from 'graphql-upload'
import { ForbiddenError } from 'apollo-server-express'
import { BlobServiceClient, ContainerClient } from '@azure/storage-blob'
import { randomSeries, getFileExtension } from 'yancey-js-util'
import { ConfigService } from '../config/config.service'
Expand Down
Loading

0 comments on commit 98184dc

Please sign in to comment.