The middleware works a lot like compression, a standard Express middleware which transparently compresses any text-based response body that emits from something in the middleware chain.
So hastily
works as an add-on to an Express server or middleware that is already serving images.
import express, { static } from 'express';
import { imageopto } from 'hastily';
const app = express();
app.use('/images', imageopto(), static('/www/images'));
app.listen(8000);
You now have an app which can serve any image from /www/images
, and optimize it with URL parameters from the Fastly Image Optimization API.
Get the length of a given chunk
Use the sharp.format
manifest to determine if the current request's file
extension matches a format that sharp can stream in to optimize.
Returns a new imageopto middleware for use in Express app.use()
.
Won't do anything if the Express app isn't already serving images!
Determine if the entity should be transformed.
Generated using TypeDoc
Add bufferred listeners to stream