{"id":49453735,"url":"https://github.com/g-wilson/wrender","last_synced_at":"2026-06-18T22:01:03.279Z","repository":{"id":55865928,"uuid":"79662222","full_name":"g-wilson/wrender","owner":"g-wilson","description":"Image compression and transformation reverse-proxy for Express apps","archived":true,"fork":false,"pushed_at":"2020-12-10T17:17:51.000Z","size":3991,"stargazers_count":14,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-29T08:52:47.489Z","etag":null,"topics":["cdn","compression","express","image-processing","jpeg","libvips","nodejs","responsive-images","sharp"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/g-wilson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-21T17:51:14.000Z","updated_at":"2023-01-28T11:31:17.000Z","dependencies_parsed_at":"2022-08-15T08:01:14.607Z","dependency_job_id":null,"html_url":"https://github.com/g-wilson/wrender","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/g-wilson/wrender","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g-wilson%2Fwrender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g-wilson%2Fwrender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g-wilson%2Fwrender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g-wilson%2Fwrender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/g-wilson","download_url":"https://codeload.github.com/g-wilson/wrender/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g-wilson%2Fwrender/sbom","scorecard":{"id":415830,"data":{"date":"2025-08-11","repo":{"name":"github.com/g-wilson/wrender","commit":"95856f16d183d7e8fa834e968eed1997cc97c9b8"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":2,"reason":"Found 3/11 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/tests.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Pinned-Dependencies","score":2,"reason":"dependency not pinned by hash detected -- score normalized to 2","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/g-wilson/wrender/tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/g-wilson/wrender/tests.yml/master?enable=pin","Warn: containerImage not pinned by hash: Dockerfile:1: pin your Docker image by updating node:8.6.0-alpine to node:8.6.0-alpine@sha256:60cd58a7a2bd9fec161f53f8886e451f92db06b91f4f72d9188eeea040d195eb","Warn: npmCommand not pinned by hash: Dockerfile:52","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   2 npmCommand dependencies pinned","Info:   0 out of   1 containerImage dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 22 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"61 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-4w2v-q235-vp99","Warn: Project is vulnerable to: GHSA-cph5-m8f7-6c5x","Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx","Warn: Project is vulnerable to: GHSA-jr5f-v2jv-69x6","Warn: Project is vulnerable to: GHSA-pp7h-53gx-mx7r","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-h452-7996-h45h","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm","Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q","Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-gp95-ppv5-3jc5","Warn: Project is vulnerable to: GHSA-54xq-cgqr-rpm3","Warn: Project is vulnerable to: GHSA-wpg7-2c88-r8xv","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-pq67-2wwv-3xjx","Warn: Project is vulnerable to: GHSA-8cj5-5rvv-wf4v","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T23:50:08.208Z","repository_id":55865928,"created_at":"2025-08-18T23:50:08.208Z","updated_at":"2025-08-18T23:50:08.208Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34508867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cdn","compression","express","image-processing","jpeg","libvips","nodejs","responsive-images","sharp"],"created_at":"2026-04-30T04:01:03.704Z","updated_at":"2026-06-18T22:01:03.273Z","avatar_url":"https://github.com/g-wilson.png","language":"JavaScript","funding_links":[],"categories":["📦 Legacy \u0026 Inactive Projects"],"sub_categories":[],"readme":"# Wrender\n\n[![NPM](https://badge.fury.io/js/wrender.svg)](https://www.npmjs.com/package/wrender)\n[![CI](https://github.com/g-wilson/wrender/workflows/tests/badge.svg)](https://github.com/g-wilson/wrender/actions)\n\nHigh-performance image compression and transformation reverse-proxy for Node.js Express apps.\n\n----\n\nThis _library_ can be used to serve up compressed and transformed images from a high-resolution origin (e.g. Amazon S3) suitable for caching and delivery by a CDN.\n\nIt provides features comparable to [Imgix](https://www.imgix.com/) and [Cloudinary](https://cloudinary.com/) for environments where you want much more customisation for how you source and handle your images. You will of course need your own CDN!\n\nIt is an open-source re-implementation of [Car Throttle](https://www.carthrottle.com/about/)'s image delivery service, which (running behind Cloudfront) handles hundreds of GBs and tens of millions of requests every day.\n\nThe image processing is extremely fast and is handled by [Sharp](https://github.com/lovell/sharp), which implements the [libvips](https://github.com/jcupitt/libvips) library as a native module. As such, Node.js [Streams](https://nodejs.org/api/stream.html) are used to abstract the handling of image data.\n\nThe recommended usage is part of a larger [express](https://expressjs.com)-based application although a simple server is provided for example, testing and non-production environments. Rate-limiting, authentication, logging, and other such features are best implemented alongside with relevant packages and therefore are not provided here, although we do present a few examples to better demonstrate certain use-cases.\n\n----\n\nUse version 3.x.x for Node 12+\n\nUse version 2.x.x for Node 10\n\n**Breaking changes:**\n\n- Recipe handler functions are treated as `async` functions, so they can now return a promise. This lets you use the Sharp [metadata api](https://sharp.pixelplumbing.com/api-input) inside recipes.\n\n- Recipe handler functions must return the Sharp `image` object for the pipeline to work.\n\n----\n\n## Compression Defaults\n\n- All images are converted to JPEG and compressed at quality level 85.\n\n- All EXIF data is stripped (including colour profiles).\n\n- All images are converted to sRGB colour space.\n\n- If include EXIF is set to true, all metadata is preserved, and an sRGB ICC colour profile is assigned.\n\n- Cache headers are set expire 1 year in the future. Set your web server or CDN to respect the headers.\n\n- Source images larger than 3000px in each dimension are not transformed and an error response is sent.\n\n## Usage\n\n```js\nconst express = require('express');\nconst wrender = require('wrender');\n\nconst app = express();\n\nconst instance = wrender({\n  quality: 90,\n  maxAge: 86400,\n});\n\napp.use('/images', instance);\n```\n\nFor a complete example with full configuration object and defaults, see below.\n\n## Recipes\n\nDifferent strategies for image handling are defined as the first parameter of the URL path. All recipe paths contain `/:origin`, which refers to the specific origin the client wishes to use. Failure to end your recipe with `/:origin` will result in an error being thrown, so ideally you should configure recipes on boot. For example, a recipe of `/hello/:origin` would match:\n\n```\n/hello/https://static.carthrottle.com/workspace/uploads/articles/dsc_6267-56ead06f7fda8.jpg\n# Note the protocol, that's important to allow HTTPS origins\n# If the origin contains a query string, you must encode the URL first:\n`/hello/http%3A%2F%2Fstatic.carthrottle.com%2Fworkspace%2Fuploads%2Farticles%2F%3Ffilename%3Ddsc_6267-56ead06f7fda8.jpg`\n```\n\n### Built-in recipes\n\nThese are the recipes that are attached if you omit `recipes` from the config object you supply to `wrender`.\n\n- **Proxy**\n  - Exposed at `wrender.recipes.proxy`\n  - The default path is `/proxy/:origin`\n  - Applies compression to the source image, but no other transformations.\n- **Resize**\n  - Exposed at `wrender.recipes.resize`\n  - The default path is `/resize/:width/:height/:origin`\n  - You can also resize by `:width` or `:height`, whilst maintaining the aspect ratio, by setting either `:width` or `:height` to `0`.\n- **Crop**\n  - Exposed at `wrender.recipes.crop`\n  - The default path is `/crop/:width/:height/:origin`\n  - Resizes the source image to the desired dimensions (maintaining aspect ratio), then performs a crop from the centre.\n\n## Origins\n\nOrigins describe where the original image content is coming from. They append the path in the recipe, replacing `/:origin` with their path, and can be used to obfuscate the original source of the images.\n\n### Built-in origins\n\nIf you omit `origins` from the config object you supply to *wrender*, the default HTTP origin will be used.\n\n- **HTTP**\n  - Fetch source images from an external HTTP(S) source\n  - Exposed at `wrender.origins.http()`\n  - Function taking entirely optional `opts`:\n    - `prefix` - add a prefix to the origin to avoid catch-all usage\n    - `defaults` - pass a set of default options to `request.defaults`\n    - `whitelist` - pass a whitelist in micromatch format for hostnames to allow (see examples)\n    - `blacklist` - pass a whitelist in micromatch format for hostnames to deny (see examples)\n  - The default path is `/:source`, which makes this origin act as a catch-all\n  - **If you require a query string** then you must url-encode the entire `:source`, otherwise Express will strip the query string\n- **FS**\n  - Loads an image from the filesystem\n  - Exposed at `wrender.origins.fs()`\n  - Function taking opts\n    - `prefix` - optionally add a prefix to the origin to avoid catch-all usage\n    - `mount` - optionally define the start mount for the source, e.g. `/data`\n  - The default path is `/:source`, which makes this origin act as a catch-all\n- **Identicon**\n  - Generates an image from the hash of an input token similar to GitHub\n  - Exposed at `wrender.origins.identicon()`\n  - URL params `/identicon/:token`\n    - `token` - input token which is hashed to generate the background colour (e.g. user id)\n  - Function taking opts\n    - `prefix` - optionally add a prefix to the origin to avoid catch-all usage (default 'identicon')\n    - `size` - size of the generated image (note: increasing this may impact memory usage). If `:size` or `:width` is used in the recipe params, the recipe params will overwrite the options here.\n    - `gridsize` - odd-numbered-integer to divide the image into pixels\n    - `saturation` - intensity of the foreground colour `[0, 1]`\n    - `lightness` - white/black level of the foreground colour `[0, 1]`\n    - `background` - rgb array for the background colour `[ r, g, b ] [0, 255]`\n    - `invert` - swaps the foreground and background colours (i.e. pixels are white on a coloured background)\n- **Initials**\n  - Generates an plain background colour with a text overlay\n  - Exposed at `wrender.origins.initials()`\n  - URL params `/initials/:token/:text`\n    - `token` - input token which is hashed to generate the background colour (e.g. user id)\n    - `text` - text to overlay (keep to 1 or 2 characters for best results)\n  - Function taking opts\n    - `prefix` - optionally add a prefix to the origin to avoid catch-all usage (default 'initials')\n    - `size` - size of the generated image (note: increasing this may impact memory usage). If `:size` or `:width` is used in the recipe params, the recipe params will overwrite the options here.\n    - `saturation` - intensity of the background colour `[0, 1]`\n    - `lightness` - white/black level of the background colour `[0, 1]`\n    - `color` - text colour (default 'white')\n    - `font` - font family for the test (default 'sans-serif')\n\n## API\n\n```js\nconst wrender = require('wrender');\n\nconst instance = wrender({\n\n  // JPEG compression level to apply\n  quality: 85, // Default\n\n  // Optionally preserve original format\n  convertGIF: true, // Default\n  convertPNG: true, // Default\n\n  // Include source image metadata\n  includeEXIF: false, // Default\n\n  // Maximum output image dimensions allowed\n  maxWidth: 3000, // Default\n  maxHeight: 3000, // Default\n\n  // Response 'max age' cache header (seconds)\n  maxAge: 31536000, // Default\n\n  // Timeout for fetching source image\n  timeout: 10000, // Default\n\n  // Only allow specified UA\n  userAgent: 'Amazon CloudFront',\n\n  // Add a callback if an error if encountered\n  onError: e =\u003e { console.error(e) },\n\n  // You can specify your own recipes, or use the pre-defined ones, or both!\n  // Skip this property to use the default recipes\n  recipes: [\n    // You can pick recipes from wrender you want to use\n    wrender.recipes.proxy,\n    wrender.recipes.resize,\n    wrender.recipes.crop,\n\n    // Or you can attach custom recipes (see documentation below)\n    wrender.createRecipe('/mirror/:origin', async image =\u003e {\n      const resized = await wrender.invokeRecipe(wrender.recipes.resize, image, { width: 200, height: 200 });\n      return resized.flop();\n    }),\n  ],\n\n  // If you want to use our recipes AND your own, that's easy to do too:\n  recipes: [\n    ...wrender.recipes,\n    wrender.createRecipe('/tiny/:origin', image =\u003e {\n      return wrender.invokeRecipe(wrender.recipes.resize, image, { width: 100, height: 100 });\n    }),\n    wrender.createRecipe('/huge/:origin', image =\u003e {\n      return wrender.invokeRecipe(wrender.recipes.resize, image, { height: 1800, width: 2560 });\n    }),\n  ]),\n\n  // Specify how images can be fetched from the origin.\n  origins: [\n\n    wrender.origins.http({\n      // Prefix the origin to allow multiple endpoints\n      prefix: '/http',\n\n      // Since the HTTP origin is based on Request, you can provide an object of defaults\n      // Underneath this will trigger `request.defaults` in an attempt to keep performance high\n      defaults: {\n        auth: { user: 'dan-kmemes-7312@hotmail.com', pass: 'correct-horse-battery-staple' },\n      },\n    }),\n\n    wrender.origins.fs({\n      // Prefix the origin as appropriate\n      prefix: '/fs',\n      // Pull data from a particular mount point\n      mount: '/data',\n    }),\n\n    // Custom origins (see documentation below)\n    wrender.createOrigin('/s3/:Bucket/:Key(*)', ({ source }) =\u003e {\n      // const s3 = new AWS.S3({ region: 'us-east-1' });\n      return s3.getObject({ Bucket, Key }).createReadStream();\n    });\n\n    // The default origin is HTTP, but without a prefix it acts as a catch-all\n    wrender.origins.http(),\n  ],\n});\n\napp.use('/images', instance);\n/**\n * Available recipes:\n * - /proxy/:origin\n * - /resize/:width/:height/:origin\n * - /crop/:width/:height/:origin\n *\n * Available origins:\n * - /http/:url\n * - /fs/:path\n * - /s3/:Bucket/:Key\n *\n * All together, available routes are, noting that the instance is mounted to \"/images\":\n * - /images/proxy/http/:url\n * - /images/proxy/fs/:path\n * - /images/proxy/s3/:Bucket/:Key\n * - /images/resize/:width/:height/http/:url\n * - /images/resize/:width/:height/fs/:path\n * - /images/resize/:width/:height/s3/:Bucket/:Key\n * - /images/crop/:width/:height/http/:url\n * - /images/crop/:width/:height/fs/:path\n * - /images/crop/:width/:height/s3/:Bucket/:Key\n */\n```\n\n## Error Handling\n\nIf an error is caught inside wrender's route handler, a blank 1x1 PNG is served as a response along with an appropriate error code (usually 404 or perhaps 500).\n\nIt is advised (but not required) to add a `onError` callback function to the constructor. This callback takes one argument (`error`) and is fired _after the response is sent_. You can use this callback to log errors wherever you like.\n\n-----\n\n## Custom Recipes\n\nCustom recipes are designed to allow you complete customisation of how images are transformed before being served to the client, by using [the Sharp API](http://sharp.dimens.io/en/stable/api-operation).\n\nRecipes are created using the `wrender.createRecipe` method with the following arguments:\n\n```js\nwrender.createRecipe(path, handler, config)\n// Where `path` is a string defining the first part of the mount point, ending in /:origin\n// Where `handler` is function, with the arguments (image, params)\n//   `image` is the Sharp instance, for you to instruct the transformation\n//   `params` is the req.params, which contain the variables in the route that you set with `path`, plus...\n//   `params.query` is req.query\n//   `params.path` is req.path\n//   `params.originalUrl` is req.originalUrl\n//   - it is always executed asynchronously (i.e. always treats the return value as a promise)\n//   - you *must* return the image (sharp object) at the end of the handler function\n// Where `config` is a plain object containing overrides to the Wrender instance config scoped to the this recipe only. Useful for customising quality or GIF conversion on a URL-basis.\n```\n\n### Recipe examples\n\nAsynchronous recipes are not supported. If you're looking to do an asynchronous operation with your recipe, consider using [the underlying `sharp` package](https://npm.im/sharp).\n\n```js\nwrender.createRecipe('/mirror/:origin', async image =\u003e {\n  const resized = await wrender.invokeRecipe(wrender.recipes.resize, image, { width: 200, height: 200 });\n  return rezized.flop();\n})\n```\n\nThis recipe will resize the image using the built-in resize recipe, to 200x200, then flop the image about the horizontal X axis, as [discussed in the Sharp API operation docs](https://sharp.pixelplumbing.com/api-operation#flop).\n\n```js\nwrender.createRecipe('/thumbnail/:source', image =\u003e wrender.invokeRecipe(wrender.recipes.resize, image, { width: 150 }))\n```\n\nBy using `wrender.invokeRecipe(recipe, image, [params])` you can call existing recipes with pre-defined values. This is useful if you wish to hide options from the URLs to prevent undesired costs or DoS attacks:\n\n```js\nconst watermark = new Buffer('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==', 'base64');\n\nwrender.createRecipe('/watermark/:origin', async image =\u003e {\n  const resized = await wrender.invokeRecipe(wrender.recipes.resize, image, { width: 200, height: 200 });\n  return resized.composite([ { input: watermark, gravity: 'northeast' });\n})\n```\n\nFollowing [the composite docs](https://sharp.pixelplumbing.com/api-composite), we can see how we would implement a watermark recipe.\n\n-----\n\n## Custom Origins\n\nNot every use-case involves fetching information from a public-facing image endpoint. Therefore *wrender* support custom origins, which can also be used to obfuscate the source of your images.\n\nOrigins are created using the `wrender.createOrigin` method with the following arguments:\n\n```js\nwrender.createOrigin(path, handler)\n// Where `path` is a string defining the last part of the mount point\n// Where `handler` is a function, optionally async, with the arguments (params)\n//   `params` is the req.params, which contain the variables in the route that you set with `path`, plus...\n//   `params.query` is req.query\n//   `params.path` is req.path\n//   `params.originalUrl` is req.originalUrl\n```\n\nEnsure params in your origin paths are unique to your origin, as conflicting params with recipes will lead to unexpected behaviours. For example, a recipe with `/resize/:width/:height/:origin` and an origin with `/fb/:width/:profile_id` will lead to `/resize/:width/:height/fb/:width/:profile_id`. Not good!\n\n`handler` expects [a readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) to be returned. Origin functions can be async, allowing you to perform (hopefully) simple async operations, to a database or an external source.\n\n### Origin examples\n\n#### Whitelist/blacklist HTTP origins\n\nIt's likely you will want to run your HTTP(S) origins through a whitelist/blacklist, to ensure only origins you allow (or prevent origins you disallow) from being hit by your *wrender*  instance. This is supported by default, and the micromatch syntax is supported:\n\n```js\napp.use('/images', wrender({\n  origins: [\n    wrender.origins.http({\n      // Only allow specified image hosts - uses micromatch syntax\n      whitelist: [ '**.giphy.com/**', 's3.amazonaws.com' ],\n      // Or blacklist specific image hosts - again, micromatch syntax\n      blacklist: [ 'hack.thepla.net' ],\n    }),\n  ],\n}));\n\n// =\u003e /images/proxy/https://s3.amazonaws.com/user-uploads.someimportantcompany.com/profiles/1505c30c51bb93545db48919b3cce7f9.jpg\n//   =\u003e Will succeed, since s3.amazonaws.com is in the whitelist\n// =\u003e /images/proxy/https://i.imgur.com/cl4Bu.gif\n//   =\u003e Will fail, since i.imgur.com isn't in the whitelist\n// =\u003e /images/proxy/https://hack.thepla.net/evilcorp.exe\n//   =\u003e Hasn't got a chance, since it's not in the whitelist, and irrelevantly isn't in the blacklist\n//   =\u003e In this example, you would need to remove the whitelist array in order to only use the blacklist\n```\n\n#### Private S3 Buckets\n\n```js\nconst wrender = require('wrender');\nconst AWS = require('aws-sdk');\n\nconst s3 = new AWS.S3({ region, secretAccessKey, accessKeyId }); // Load these from environment variables\n\nmodule.exports = wrender.createOrigin('/s3/:Bucket/:Key(*)', ({ Bucket, Key }) =\u003e {\n  return s3.getObject({ Bucket, Key }).createReadStream()\n});\n\n// =\u003e /images/proxy/s3/user-uploads.someimportantcompany.com/profiles/1505c30c51bb93545db48919b3cce7f9.jpg\n//   =\u003e Streams from S3, as long as the s3 instance has the correct permissions\n//   =\u003e Super-effective with EC2 instance roles \u0026 ECS task roles\n```\n\n#### Facebook Profile Pictures\n\n```js\nconst request = require('request');\nconst wrender = require('wrender');\n\nmodule.exports = wrender.createOrigin('/fb/:profile_id', ({ profile_id }) =\u003e {\n  return request(`https://graph.facebook.com/${profile_id}/picture?width=1024\u0026height=1024`);\n});\n\n// =\u003e /images/proxy/fb/113741208636938\n//   =\u003e https://graph.facebook.com/113741208636938/picture?width=1024\u0026height=1024\n```\n\nThis is also a good example for using custom origins to rewrite URLs.\n\n#### Lookup image data from a model\n\n```js\nconst wrender = require('wrender');\nconst AWS = require('aws-sdk');\nconst images = require('../models/images');\nconst s3 = new AWS.S3({ region, secretAccessKey, accessKeyId });\n\nmodule.exports = wrender.createOrigin('/users/:image_id', async ({ image_id }) =\u003e {\n  const { bucket, key } = await images.findById(image_id);\n  return s3.getObject({ Bucket: bucket, Key: key }).createReadStream();\n});\n\n// =\u003e /images/resize/200/200/users/9ff4a3cf5fe1a735ec96f142a2081f3e\n//   =\u003e s3://user-uploads.someimportantcompany.com/profiles/9ff4a3cf5fe1a735ec96f142a2081f3e.jpg\n```\n\nHopefully, `images.findById` will be nicely cached or easy to pull up.\n\n-----\n\n## Docker\n\n```sh\n$ docker build -t g-wilson/wrender:dev .\n$ docker run -it -p 3010:3010 g-wilson/wrender:dev\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg-wilson%2Fwrender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fg-wilson%2Fwrender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg-wilson%2Fwrender/lists"}