Skip to content

Commit

Permalink
chore: remove deprecated bodyParser in favor of express methods (#3388)
Browse files Browse the repository at this point in the history
Co-authored-by: ehmicky <[email protected]>
  • Loading branch information
tinfoil-knight and ehmicky authored Sep 23, 2021
1 parent 863b20c commit 23469be
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 19 deletions.
1 change: 0 additions & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"ascii-table": "0.0.9",
"backoff": "^2.5.0",
"better-opn": "^2.1.1",
"body-parser": "^1.19.0",
"boxen": "^5.0.0",
"chalk": "^4.0.0",
"chokidar": "^3.0.2",
Expand Down
1 change: 0 additions & 1 deletion src/functions-templates/js/oauth-passport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"author": "Netlify",
"license": "MIT",
"dependencies": {
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
Expand Down
5 changes: 2 additions & 3 deletions src/functions-templates/js/oauth-passport/{{name}}.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// details: https://markus.oberlehner.net/blog/implementing-an-authentication-flow-with-passport-and-netlify-functions/

const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const express = require('express')
const passport = require('passport')
Expand All @@ -13,8 +12,8 @@ applyPassportStrategies()

const app = express()

app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(cookieParser())
app.use(passport.initialize())

Expand Down
5 changes: 2 additions & 3 deletions src/functions-templates/js/serverless-ssr/app/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Express App */
const process = require('process')

const bodyParser = require('body-parser')
const compression = require('compression')
const cors = require('cors')
const express = require('express')
Expand Down Expand Up @@ -92,8 +91,8 @@ module.exports = function expressApp(functionName) {

// Apply express middlewares
router.use(cors())
router.use(bodyParser.json())
router.use(bodyParser.urlencoded({ extended: true }))
router.use(express.json())
router.use(express.urlencoded({ extended: true }))

return app
}
Expand Down
1 change: 0 additions & 1 deletion src/functions-templates/js/serverless-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"author": "Netlify",
"license": "MIT",
"dependencies": {
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.17.1",
Expand Down
5 changes: 2 additions & 3 deletions src/lib/functions/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const bodyParser = require('body-parser')
const jwtDecode = require('jwt-decode')

const { log, error: errorExit } = require('../../utils/command-helpers')
Expand Down Expand Up @@ -118,12 +117,12 @@ const getFunctionsServer = async function ({ functionsRegistry, siteUrl, prefix
app.set('query parser', 'simple')

app.use(
bodyParser.text({
express.text({
limit: '6mb',
type: ['text/*', 'application/json'],
}),
)
app.use(bodyParser.raw({ limit: '6mb', type: '*/*' }))
app.use(express.raw({ limit: '6mb', type: '*/*' }))
app.use(createFormSubmissionHandler({ functionsRegistry, siteUrl }))
app.use(
expressLogging(console, {
Expand Down
3 changes: 1 addition & 2 deletions tests/utils/external-server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const bodyParser = require('body-parser')
const express = require('express')

const startExternalServer = () => {
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
app.use(express.urlencoded({ extended: true }))
app.all('*', function onRequest(req, res) {
res.json({ url: req.url, body: req.body, method: req.method })
})
Expand Down
7 changes: 3 additions & 4 deletions tests/utils/mock-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { isDeepStrictEqual } = require('util')

const bodyParser = require('body-parser')
const express = require('express')

const addRequest = (requests, request) => {
Expand All @@ -15,9 +14,9 @@ const addRequest = (requests, request) => {
const startMockApi = ({ routes }) => {
const requests = []
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(bodyParser.raw())
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(express.raw())

routes.forEach(({ method = 'get', path, response = {}, status = 200, requestBody }) => {
app[method.toLowerCase()](`/api/v1/${path}`, function onRequest(req, res) {
Expand Down

1 comment on commit 23469be

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 352 MB

Please sign in to comment.