Compression for HTTP microservices built with Micro
Install micro-compress
using npm:
npm install --save micro-compress
Just wrap your Micro HTTP microservice with this module:
const {send, json} = require('micro');
const compress = require('micro-compress');
module.exports = compress(async (req, res) => {
const body = await json(req);
send(res, 200, body);
});
Options for the compression
module are passed as the first parameter:
const {Z_BEST_COMPRESSION} = require('zlib');
const {send, json} = require('micro');
const compress = require('micro-compress');
module.exports = compress({level: Z_BEST_COMPRESSION}, async (req, res) => {
const body = await json(req);
send(res, 200, body);
});
Name | Type | Description |
---|---|---|
opts | object |
Optional. Options passed to compression |
fn | function |
The request handler to wrap |
For available options see compression
's options.
MIT © Joakim Carlstein