Skip to content

Instantly share code, notes, and snippets.

@tisseurdetoile
Created October 1, 2018 08:46
Show Gist options
  • Save tisseurdetoile/f5f3b586327bf25435822629fbe82d69 to your computer and use it in GitHub Desktop.
Save tisseurdetoile/f5f3b586327bf25435822629fbe82d69 to your computer and use it in GitHub Desktop.
middleware for json-server
/**
* ts_middleware.js for json-server
* add a timestamp _ts variable for entry
* https://github.com/typicode/json-server
*/
module.exports = function(req, res, next) {
if (req.method === 'PUT' || req.method === 'POST') {
if (req.body) {
req.body['_TS'] = Math.round(new Date().getTime() / 1000)
}
}
next()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment