Skip to content

Commit 9e2f3fd

Browse files
nischay30fhinkel
andauthored
Replaced all occurrences of body-parser from the samples (GoogleCloudPlatform#2223)
* replaced deprecated body-parser from app-engine samples * replaced deprecated body-parser from cloud-sql samples * replaced deprecated body-parser from endpoints samples * replaced deprecated body-parser from clud run samples * fixed failing test case of appengine endpoints Co-authored-by: F. Hinkelmann <franziska.hinkelmann@gmail.com>
1 parent c49df1f commit 9e2f3fd

File tree

24 files changed

+30
-38
lines changed

24 files changed

+30
-38
lines changed

appengine/building-an-app/update/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"author": "Google Inc.",
2020
"license": "Apache-2.0",
2121
"dependencies": {
22-
"body-parser": "^1.18.2",
2322
"express": "^4.16.3"
2423
},
2524
"devDependencies": {

appengine/building-an-app/update/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
// [START app]
1818
const express = require('express');
19-
const bodyParser = require('body-parser');
2019
const path = require('path');
2120

2221
const app = express();
2322

2423
// [START enable_parser]
25-
app.use(bodyParser.urlencoded({extended: true}));
24+
// This middleware is available in Express v4.16.0 onwards
25+
app.use(express.json({extended: true}));
2626
// [END enable_parser]
2727

2828
app.get('/', (req, res) => {

appengine/endpoints/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
'use strict';
1616

1717
const express = require('express');
18-
const bodyParser = require('body-parser');
1918

2019
const app = express();
21-
app.use(bodyParser.json());
20+
21+
// This middleware is available in Express v4.16.0 onwards
22+
app.use(express.json());
2223

2324
app.post('/echo', (req, res) => {
2425
res.status(200).json({message: req.body.message});

appengine/endpoints/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"test": "npm run unit-test"
2020
},
2121
"dependencies": {
22-
"body-parser": "^1.18.3",
2322
"chai": "^4.2.0",
2423
"express": "^4.16.4",
2524
"wait-port": "^0.2.7"

appengine/endpoints/test/app.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
const express = require('express');
1818
const path = require('path');
19-
const proxyquire = require('proxyquire').noCallThru();
19+
const proxyquire = require('proxyquire').noPreserveCache();
2020
const request = require('supertest');
2121
const sinon = require('sinon');
2222
const assert = require('assert');

appengine/pubsub/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
'use strict';
1616

1717
const express = require('express');
18-
const bodyParser = require('body-parser');
1918
const {OAuth2Client} = require('google-auth-library');
2019
const path = require('path');
2120
const process = require('process'); // Required for mocking environment variables
@@ -35,8 +34,9 @@ const app = express();
3534
app.set('view engine', 'pug');
3635
app.set('views', path.join(__dirname, 'views'));
3736

38-
const formBodyParser = bodyParser.urlencoded({extended: false});
39-
const jsonBodyParser = bodyParser.json();
37+
// This middleware is available in Express v4.16.0 onwards
38+
const formBodyParser = express.urlencoded({extended: false});
39+
const jsonBodyParser = express.json();
4040

4141
// List of all messages received by this instance
4242
const messages = [];

appengine/pubsub/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
},
1515
"dependencies": {
1616
"@google-cloud/pubsub": "^2.5.0",
17-
"body-parser": "^1.19.0",
1817
"express": "^4.17.1",
1918
"google-auth-library": "^7.0.0",
2019
"path": "^0.12.7",

appengine/storage/flexible/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const process = require('process'); // Required to mock environment variables
2020
const {format} = require('util');
2121
const express = require('express');
2222
const Multer = require('multer');
23-
const bodyParser = require('body-parser');
2423

2524
// By default, the client will authenticate using the service account file
2625
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
@@ -34,7 +33,9 @@ const storage = new Storage();
3433

3534
const app = express();
3635
app.set('view engine', 'pug');
37-
app.use(bodyParser.json());
36+
37+
// This middleware is available in Express v4.16.0 onwards
38+
app.use(express.json());
3839

3940
// Multer is required to process file uploads and make them available via
4041
// req.files.

appengine/storage/flexible/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
},
1111
"dependencies": {
1212
"@google-cloud/storage": "^5.3.0",
13-
"body-parser": "^1.19.0",
1413
"express": "^4.17.0",
1514
"multer": "^1.4.2",
1615
"pug": "^3.0.0"

appengine/storage/standard/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const process = require('process'); // Required to mock environment variables
2020
const {format} = require('util');
2121
const express = require('express');
2222
const Multer = require('multer');
23-
const bodyParser = require('body-parser');
2423

2524
// By default, the client will authenticate using the service account file
2625
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
@@ -34,7 +33,9 @@ const storage = new Storage();
3433

3534
const app = express();
3635
app.set('view engine', 'pug');
37-
app.use(bodyParser.json());
36+
37+
// This middleware is available in Express v4.16.0 onwards
38+
app.use(express.json());
3839

3940
// Multer is required to process file uploads and make them available via
4041
// req.files.

0 commit comments

Comments
 (0)