serve-webp

1.0.0 • Public • Published

serve-webp

Create a new middleware function to serve images from within a given root directory. The images to serve will be determined by combining req.url with the provided root directory. When browser support webp,this module will convert the local images(jpg,gif,png) to webp and save into specify cache directory and response as webp,otherwise it will call next() to move on to the next middleware

Installation

npm install serve-webp

Usage

const serveWebp = require('serve-webp');
const app = require('express')();
app.get('/*',serveWebp({
    root:path.resolve(process.cwd()),
    cache:path.resolve(process.cwd(),'webp')
}));
 
 

config

root

images root directory

use path.join(root, req.url) as file path

cache

webp cache directory

Package Sidebar

Install

npm i serve-webp

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • ljwrer