Skip to content

Commit

Permalink
feat: added cors to express
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLzq committed Mar 7, 2022
1 parent ce3c021 commit cfd78b1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions example/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"dependencies": {
"@sinclair/typebox": "^0.23.4",
"ajv": "^6",
"cors": "^2.8.5",
"express": "^4.17.3",
"http-errors": "^2.0.0",
"mongoose": "^6.2.4",
"morgan": "^1.10.0",
"swagger-ui-express": "^4.3.0"
},
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/http-errors": "^1.8.2",
"@types/morgan": "^1.9.3",
Expand Down
3 changes: 2 additions & 1 deletion example/express/src/network/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express from 'express'
import mongoose from 'mongoose'
import morgan from 'morgan'
import cors from 'cors'

import { applyRoutes } from './router'

Expand All @@ -16,7 +17,7 @@ class Server {
}

private _config() {
this._app.set('port', PORT)
this._app.use(cors())
this._app.use(morgan('dev'))
this._app.use(express.json())
this._app.use(express.urlencoded({ extended: false }))
Expand Down
20 changes: 19 additions & 1 deletion example/express/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@
dependencies:
"@types/node" "*"

"@types/cors@^2.8.12":
version "2.8.12"
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080"
integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==

"@types/eslint-scope@^3.7.3":
version "3.7.3"
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224"
Expand Down Expand Up @@ -1139,6 +1144,14 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==

cors@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
dependencies:
object-assign "^4"
vary "^1"

create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
Expand Down Expand Up @@ -2873,6 +2886,11 @@ null-check@^1.0.0:
resolved "https://registry.yarnpkg.com/null-check/-/null-check-1.0.0.tgz#977dffd7176012b9ec30d2a39db5cf72a0439edd"
integrity sha1-l33/1xdgErnsMNKjnbXPcqBDnt0=

object-assign@^4:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=

object-inspect@^1.11.0, object-inspect@^1.9.0:
version "1.12.0"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.0.tgz#6e2c120e868fd1fd18cb4f18c31741d0d6e776f0"
Expand Down Expand Up @@ -4043,7 +4061,7 @@ validate-npm-package-license@^3.0.1:
spdx-correct "^3.0.0"
spdx-expression-parse "^3.0.0"

vary@~1.1.2:
vary@^1, vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
Expand Down
3 changes: 2 additions & 1 deletion lib/src/functions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ export { applyRoutes }
content: `import express from 'express'
import mongoose from 'mongoose'
import morgan from 'morgan'
import cors from 'cors'
import { applyRoutes } from './router'
Expand All @@ -676,7 +677,7 @@ class Server {
}
private _config() {
this._app.set('port', PORT)
this._app.use(cors())
this._app.use(morgan('dev'))
this._app.use(express.json())
this._app.use(express.urlencoded({ extended: false }))
Expand Down
4 changes: 2 additions & 2 deletions lib/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ module.exports = async ({
cliProgress.Presets.shades_classic
)

const expressProdPackages = 'express morgan swagger-ui-express'
const expressProdPackages = 'express morgan swagger-ui-express cors'
const fastifyProdPackages = 'fastify fastify-swagger'
const prodPackages = `${manager} http-errors mongoose @sinclair/typebox ajv@^6 ${
fastify ? fastifyProdPackages : expressProdPackages
}`

const expressDevPackages = `@types/express @types/morgan @types/swagger-ui-express`
const expressDevPackages = `@types/express @types/morgan @types/swagger-ui-express @types/cors`
const fastifyDevPackages = ''
const devPackages = `${manager} -D \
@types/http-errors \
Expand Down

0 comments on commit cfd78b1

Please sign in to comment.