Skip to content

Commit fcf706c

Browse files
authored
Merge pull request #210 from bcgov/bugfix/explicitjsonparsing
Refactor express.json middleware to be route explicit
2 parents b94bb30 + 806f7fc commit fcf706c

File tree

15 files changed

+13
-39
lines changed

15 files changed

+13
-39
lines changed

.github/actions/deploy-to-environment/action.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ runs:
5050
--set image.repository=ghcr.io/${{ github.repository_owner }}
5151
--set image.tag=sha-$(git rev-parse --short HEAD)
5252
--set route.host=${{ inputs.acronym }}-${{ inputs.namespace_environment }}-${{ inputs.job_name }}.apps.silver.devops.gov.bc.ca
53-
--set config.configMap.OBJECTSTORAGE_KEY=${{ inputs.acronym }}/${{ inputs.namespace_environment }}
5453
--timeout 10m
5554
--wait
5655

.github/environments/values.dev.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ config:
1919
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuy7zfh2ZgpDV5mH/aXyLDTddZK81rGakJcTy4KvCNOkDDxt1KAhW02lmbCo8YhHCOzjNZBp1+Vi6QiMRgBqAe2GTPZYEiV70aXfROGZe3Nvwcjbtki6HoyRte3SpqLJEIPL2F+hjJkw1UPGnjPTWZkEx9p74b9i3BjuE8RnjJ0Sza2MWw83zoQUZEJRGiopSL0yuVej6t2LO2btVdVf7QuZfPt9ehkcQYlPKpVvJA+pfeqPAdnNt7OjEIeYxinjurZr8Z04hz8UhkRefcWlSbFzFQYmL7O7iArjW0bsSvq8yNUd5r0KCOQkFduwZy26yTzTxj8OLFT91fEmbBBl4rQIDAQAB
2020
KC_REALM: standard
2121
KC_SERVERURL: "https://dev.loginproxy.gov.bc.ca/auth"
22-
SERVER_BODYLIMIT: 30mb
2322
# SERVER_LOGFILE: ~
2423
SERVER_LOGLEVEL: http
2524
SERVER_PORT: "3000"

.github/environments/values.prod.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ config:
1919
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmHiuPKOkpkq4GXN1ktr23rJtDl6Vdu/Y37ZAd3PnQ8/IDfAODvy1Y81aAUZicKe9egolv+OTRANN3yOg+TAbRhkeXLE5p/473EK0aQ0NazTCuWo6Am3oDQ7Yt8x0pw56/qcLtkTuXNyo5EnVV2Z2BzCnnaL31JOhyitolku0DNT6GDoRBmT4o2ItqEVHk5nM25cf1t2zbwI2790W6if1B2qVRkxxivS8tbH7nYC61Is3XCPockKptkH22cm2ZQJmtYd5sZKuXaGsvtyzHmn8/l0Kd1xnHmUu4JNuQ67YiNZGu3hOkrF0Js3BzAk1Qm4kvYRaxbJFCs/qokLZ4Z0W9wIDAQAB
2020
KC_REALM: standard
2121
KC_SERVERURL: "https://loginproxy.gov.bc.ca/auth"
22-
SERVER_BODYLIMIT: 30mb
2322
# SERVER_LOGFILE: ~
2423
SERVER_LOGLEVEL: http
2524
SERVER_PORT: "3000"

.github/environments/values.test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ config:
1919
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiFdv9GA83uHuy8Eu9yiZHGGF9j6J8t7FkbcpaN81GDjwbjsIJ0OJO9dKRAx6BAtTC4ubJTBJMPvQER5ikOhIeBi4o25fg61jpgsU6oRZHkCXc9gX6mrjMjbsPaf3/bjjYxP5jicBDJQeD1oRa24+tiGggoQ7k6gDEN+cRYqqNpzC/GQbkUPk8YsgroncEgu8ChMh/3ERsLV2zorchMANUq76max16mHrhtWIQxrb/STpSt4JuSlUzzBV/dcXjJe5gywZHe0jAutFhNqjHzHdgyaC4RAd3eYQo+Kl/JOgy2AZrnx+CiPmvOJKe9tAW4k4H087ng8aVE40v4HW/FEbnwIDAQAB
2020
KC_REALM: standard
2121
KC_SERVERURL: "https://test.loginproxy.gov.bc.ca/auth"
22-
SERVER_BODYLIMIT: 30mb
2322
# SERVER_LOGFILE: ~
2423
SERVER_LOGLEVEL: http
2524
SERVER_PORT: "3000"

app/app.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const compression = require('compression');
33
const config = require('config');
44
const cors = require('cors');
55
const express = require('express');
6-
const { unless } = require('express-unless');
76
const { ValidationError } = require('express-validation');
87

98
const { AuthMode, DEFAULTCORS } = require('./src/components/constants');
@@ -31,17 +30,8 @@ let probeId;
3130
let queueId;
3231

3332
const app = express();
34-
const jsonParser = express.json({ limit: config.get('server.bodyLimit') });
35-
jsonParser.unless = unless;
3633
app.use(compression());
3734
app.use(cors(DEFAULTCORS));
38-
app.use(jsonParser.unless({
39-
path: [{
40-
// Matches on only the createObject and updateObject endpoints
41-
url: /.*(?<!permission)\/object(\/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})?(\/)?(\?.*)?$/i,
42-
methods: ['PUT']
43-
}]
44-
}));
4535
app.use(express.urlencoded({ extended: true }));
4636

4737
// Skip if running tests

app/config/custom-environment-variables.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"secretAccessKey": "OBJECTSTORAGE_SECRETACCESSKEY"
3232
},
3333
"server": {
34-
"bodyLimit": "SERVER_BODYLIMIT",
3534
"defaultTempExpiresIn": "SERVER_TEMP_EXPIRESIN",
3635
"hardReset": "SERVER_HARDRESET",
3736
"logFile": "SERVER_LOGFILE",

app/config/default.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"username": "app"
99
},
1010
"server": {
11-
"bodyLimit": "30mb",
1211
"defaultTempExpiresIn": "300",
1312
"logLevel": "http",
1413
"maxRetries": "3",

app/package-lock.json

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"date-fns": "^2.30.0",
4242
"express": "^4.18.2",
4343
"express-basic-auth": "^1.2.1",
44-
"express-unless": "^2.1.3",
4544
"express-validation": "^4.1.0",
4645
"express-winston": "^4.2.0",
4746
"js-yaml": "^4.1.0",

app/src/routes/v1/bucket.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const router = require('express').Router();
1+
const express = require('express');
2+
const router = express.Router();
23

34
const { Permissions } = require('../../components/constants');
45
const { bucketController, syncController } = require('../../controllers');
@@ -10,7 +11,7 @@ router.use(checkAppMode);
1011
router.use(requireSomeAuth);
1112

1213
/** Creates a bucket */
13-
router.put('/', bucketValidator.createBucket, (req, res, next) => {
14+
router.put('/', express.json(), bucketValidator.createBucket, (req, res, next) => {
1415
bucketController.createBucket(req, res, next);
1516
});
1617

@@ -35,7 +36,7 @@ router.get('/', bucketValidator.searchBuckets, (req, res, next) => {
3536
});
3637

3738
/** Updates a bucket */
38-
router.patch('/:bucketId', bucketValidator.updateBucket, hasPermission(Permissions.UPDATE), (req, res, next) => {
39+
router.patch('/:bucketId', express.json(), bucketValidator.updateBucket, hasPermission(Permissions.UPDATE), (req, res, next) => {
3940
bucketController.updateBucket(req, res, next);
4041
});
4142

0 commit comments

Comments
 (0)