Created
October 1, 2018 08:46
-
-
Save tisseurdetoile/f5f3b586327bf25435822629fbe82d69 to your computer and use it in GitHub Desktop.
middleware for json-server
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
/** | |
* 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