Skip to content

Overview

@urami/core contains API handler for image optimization on server endpoints.

It's designed to be used with any frameworks that able to pass input as a Request interface of Fetch API, and return output as Response interface of Fetch API.

If your backend framework does not comply with Fetch API Request object, just mocking url and headers at minimum to be able to use Urami Core.

ts
export type RequestHandler = (request: Pick<Request, 'url' | 'headers'>) => Promise<Response>
export type RequestHandler = (request: Pick<Request, 'url' | 'headers'>) => Promise<Response>

Lifecycle

  1. API will get url, width, and quality from URL query string
  2. Check if image is allowed to be optimized via remoteDomains option
  3. If you're running as a production server, API will check if request is coming from allowed domain via allowedDomains option
  4. API will try to figure out which is the best image format to be served to user
  5. If image is cached and not expired, API will serve cached image
  6. Otherwise, API will download image from url and optimize it
  7. Optimized image will be cached, and served to user