-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response data with X-Total-Count #1015
Comments
You can overwrite router.render method like this:
|
A bit late but this might help: // middlewares.cjs
module.exports = (req, res, next) => {
const _send = res.send;
res.send = function (data) {
if (req.method === "GET") {
data = JSON.stringify({
Data: JSON.parse(data),
TotalCount: this.getHeader("X-Total-Count") ?? null,
});
}
_send.call(this, data);
};
next();
}; and run json-server -m middlewares.cjs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What do I need to to convert the response object to return
{
TotalCount: X-Total-Count
Data: [... dto goes here ]
}
Can I modify the response in middleware to return an object like above.
The text was updated successfully, but these errors were encountered: