From 8d663d469f53f94bd2dc001b8447154517294330 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Wed, 6 Sep 2017 12:40:29 +0530 Subject: [PATCH 1/3] Supporting overriding HTTP Method via X-HTTP-Method-Override header --- package.json | 1 + src/app.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/package.json b/package.json index ad65dda3..4897f17c 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "http-aws-es": "^1.1.3", "joi": "^8.0.5", "lodash": "^4.16.4", + "method-override": "^2.3.9", "pg": "^4.5.5", "pg-native": "^1.10.0", "sequelize": "^3.23.0", diff --git a/src/app.js b/src/app.js index 5d6738d2..1ed6e3b5 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,5 @@ import express from 'express'; +import methodOverride from 'method-override' import _ from 'lodash'; import bodyParser from 'body-parser'; import config from 'config'; @@ -11,6 +12,9 @@ import analytics from './events/analytics'; const app = express(); +// allows overriding HTTP Method +app.use(methodOverride('X-HTTP-Method-Override')) + // ======================= // configuration ========= // ======================= From 0131191144df395afa41571cce9b6f8e0a3b089a Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Wed, 6 Sep 2017 12:50:17 +0530 Subject: [PATCH 2/3] Explicitly specified that only original POST can be converted into different request method --- src/app.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index 1ed6e3b5..dae7155b 100644 --- a/src/app.js +++ b/src/app.js @@ -13,7 +13,9 @@ import analytics from './events/analytics'; const app = express(); // allows overriding HTTP Method -app.use(methodOverride('X-HTTP-Method-Override')) +// both arguments to the methodOverride are optional because they are the default +// values, but we are specifying them to avoid any future change in defaults +app.use(methodOverride('X-HTTP-Method-Override', {methods : ['POST'] })) // ======================= // configuration ========= From a5040117423516d99a8fe43bb65cba434937b133 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Wed, 6 Sep 2017 12:55:14 +0530 Subject: [PATCH 3/3] Fixed lint errors --- src/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index dae7155b..b9c5b63c 100644 --- a/src/app.js +++ b/src/app.js @@ -1,5 +1,5 @@ import express from 'express'; -import methodOverride from 'method-override' +import methodOverride from 'method-override'; import _ from 'lodash'; import bodyParser from 'body-parser'; import config from 'config'; @@ -15,7 +15,7 @@ const app = express(); // allows overriding HTTP Method // both arguments to the methodOverride are optional because they are the default // values, but we are specifying them to avoid any future change in defaults -app.use(methodOverride('X-HTTP-Method-Override', {methods : ['POST'] })) +app.use(methodOverride('X-HTTP-Method-Override', { methods: ['POST'] })); // ======================= // configuration =========