A reverse proxy server to convert, cache and respond images in WebP format.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.dockerignore
.eslintignore
.eslintrc.json
.gitignore
.travis.yml
Dockerfile
LICENSE
README.md
index.js
index.mjs
main.js
main.mjs
package-lock.json
package.json

README.md

malasada Malasada

NPM version build status node version

A reverse proxy server to convert, cache and respond images in WebP format. Can be used standalone or as a Koa middleware.

Install

NPM

You'll need to install WebP binaries on your server, please see node-webp manual for installation.

Docker

You can also run malasada with Docker:

docker run --name malasada -p 80:3002 -v /path/to/config.json:/app/config.json -v /path/to/cache:/app/cache -d mudkip/malasada

Replace /path/to with the correct location of config.json and cache.

Configruation

A config.json file is required to run this program.

{
    "backendType": "remote",
    "backend": "http://upload.wikimedia.org",
    "maxAge": 3628800000,
    "forceWebP": false,
    "cacheRootPath": "/var/cache/malasada",
    "requestHeaders": {},
    "queue": 1,
    "port": 3002
  }
  • backendType: Can be remote or local.
  • backend: May be a http or https host when backendType is remote, or a local directory when backendType is local. Required.
  • maxAge: The max age (in milliseconds) sent to browsers.
  • forceWebP: When is true, the server always response WebP images when possible, otherwise it only respond WebP images when it is accepted by browsers in Accept header.
  • cacheRootPath: Where the cache files saves, defaults to cache directory of this program.
  • requestHeaders: Additional headers sent to backend, only useful when backendType is remote.
  • queue: Simultaneous WebP conversion tasks, defaults to 1.
  • port: The listen port of the server, only useful when used standalone.

Usage

When installed globally, it can be run with malasada --config config.json.

You can also use it as a middleware in your Koa instance:

const Koa = require('koa');
const malasada = require('malasada');

const app = new Koa();
app.use(malasada(config));

Remember this program is not designed to be a full-featured reverse proxy, the backend server should only be a static file server.

Cache Deletion

A PURGE request, or a GET request with /purge prefix can be used to delete cache of a certain path.

License

MIT

Notice

While the sweet malasada is used on 52Poké Wiki to handle hundreds of thousands requests daily, it currently lacks tests and significant features such as proper cache control and cache size management.

Pull requests and issues are welcome.