From 8fe56852e0f7673dfb8f83405f5b506de07fb28c Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 21 Apr 2020 18:25:53 +0100 Subject: [PATCH] Moved request-id mw into parent app - Moved request-id from shared to parent as it is not shared - This file is only used in one place, this updates the code structure to reflect this - This is one of many similar changes needed to make it easier to refactor to the existing setup --- core/server/web/parent/app.js | 3 ++- core/server/web/parent/middleware/index.js | 3 +++ .../{shared/middlewares => parent/middleware}/request-id.js | 0 core/server/web/shared/middlewares/index.js | 4 ---- test/unit/web/{ => parent}/middleware/request-id_spec.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 core/server/web/parent/middleware/index.js rename core/server/web/{shared/middlewares => parent/middleware}/request-id.js (100%) rename test/unit/web/{ => parent}/middleware/request-id_spec.js (92%) diff --git a/core/server/web/parent/app.js b/core/server/web/parent/app.js index a9a1b71f40..1ec4d68487 100644 --- a/core/server/web/parent/app.js +++ b/core/server/web/parent/app.js @@ -5,6 +5,7 @@ const config = require('../../config'); const compress = require('compression'); const netjet = require('netjet'); const shared = require('../shared'); +const mw = require('./middleware'); const escapeRegExp = require('lodash.escaperegexp'); const {URL} = require('url'); const sentry = require('../../sentry'); @@ -20,7 +21,7 @@ module.exports = function setupParentApp(options = {}) { // (X-Forwarded-Proto header will be checked, if present) parentApp.enable('trust proxy'); - parentApp.use(shared.middlewares.requestId); + parentApp.use(mw.requestId); parentApp.use(shared.middlewares.logRequest); // Register event emmiter on req/res to trigger cache invalidation webhook event diff --git a/core/server/web/parent/middleware/index.js b/core/server/web/parent/middleware/index.js new file mode 100644 index 0000000000..31975fcda5 --- /dev/null +++ b/core/server/web/parent/middleware/index.js @@ -0,0 +1,3 @@ +module.exports = { + requestId: require('./request-id') +}; diff --git a/core/server/web/shared/middlewares/request-id.js b/core/server/web/parent/middleware/request-id.js similarity index 100% rename from core/server/web/shared/middlewares/request-id.js rename to core/server/web/parent/middleware/request-id.js diff --git a/core/server/web/shared/middlewares/index.js b/core/server/web/shared/middlewares/index.js index fd958e47b7..db84727f7e 100644 --- a/core/server/web/shared/middlewares/index.js +++ b/core/server/web/shared/middlewares/index.js @@ -51,10 +51,6 @@ module.exports = { return require('./pretty-urls'); }, - get requestId() { - return require('./request-id'); - }, - get uncapitalise() { return require('./uncapitalise'); }, diff --git a/test/unit/web/middleware/request-id_spec.js b/test/unit/web/parent/middleware/request-id_spec.js similarity index 92% rename from test/unit/web/middleware/request-id_spec.js rename to test/unit/web/parent/middleware/request-id_spec.js index 878d966e5f..6b49efd393 100644 --- a/test/unit/web/middleware/request-id_spec.js +++ b/test/unit/web/parent/middleware/request-id_spec.js @@ -2,7 +2,7 @@ const should = require('should'); const sinon = require('sinon'); const validator = require('validator'); -const requestId = require('../../../../core/server/web/shared/middlewares/request-id'); +const requestId = require('../../../../../core/server/web/parent/middleware/request-id'); describe('Request ID middleware', function () { var res, req, next;