'How to send api response compressed in nuxt.js

Chrome Lighthouse tells me that I could save like 90% of the transfered bytes by compressing my api route

How could I modify this code (api/something.js) to enable compression?

export default {
    path: '/api/something',
    async handler(req, res) {
        let data = await obtainDataSomehow();
        res.end(JSON.stringify(data));
    }
}

Static files and rendered routes are already compressed, I only have trouble with api routes.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source