Created
August 28, 2014 01:40
-
-
Save suissa/6bf86d98a5cfb4a71a16 to your computer and use it in GitHub Desktop.
Using _method input hidden to override HTTP verbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var methodOverride = require('method-override') | |
// NOTE: when using req.body, you must fully parse the request body | |
// before you call methodOverride() in your middleware stack, | |
// otherwise req.body will not be populated. | |
app.use(methodOverride(function(req, res){ | |
if (req.body && typeof req.body === 'object' && '_method' in req.body) { | |
// look in urlencoded POST bodies and delete it | |
var method = req.body._method | |
delete req.body._method | |
return method | |
} | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment