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
- API will get
url,width, andqualityfrom URL query string - Check if image is allowed to be optimized via
remoteDomainsoption - If you're running as a production server, API will check if request is coming from allowed domain via
allowedDomainsoption - API will try to figure out which is the best image format to be served to user
- If image is cached and not expired, API will serve cached image
- Otherwise, API will download image from
urland optimize it - Optimized image will be cached, and served to user