Skip to content

Commit

Permalink
[FEATURE] csp: lazy require body-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasso85 committed Jun 9, 2020
1 parent ebd252d commit 0c7a241
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/middleware/csp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const parseurl = require("parseurl");
const Router = require("router");
const bodyParser = require("body-parser");
const querystring = require("querystring");

const log = require("@ui5/logger").getLogger("server:middleware:csp");
Expand Down Expand Up @@ -61,7 +60,10 @@ function createMiddleware(sCspUrlParameterName, oConfig) {
const router = new Router();
// .csplog
// body parser is required to parse csp-report in body (json)
router.post("/.ui5/csp/report.csplog", bodyParser.json({type: "application/csp-report"}));
if (serveCSPReports) {
const bodyParser = require("body-parser");
router.post("/.ui5/csp/report.csplog", bodyParser.json({type: "application/csp-report"}));
}
router.post("/.ui5/csp/report.csplog", function(req, res, next) {
if (req.headers["content-type"] === "application/csp-report") {
if (!serveCSPReports) {
Expand Down

0 comments on commit 0c7a241

Please sign in to comment.