0.2.0 • Published 6 years ago

malasada v0.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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 second) 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.