Skip to content

Instantly share code, notes, and snippets.

@suissa
Created August 28, 2014 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suissa/6bf86d98a5cfb4a71a16 to your computer and use it in GitHub Desktop.
Save suissa/6bf86d98a5cfb4a71a16 to your computer and use it in GitHub Desktop.
Using _method input hidden to override HTTP verbs
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