Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

badges/svg-to-image-proxy

Repository files navigation

svg-to-image-proxy

⚠️ Deprecated

This package is now deprecated and archived. Shields.io has migrated to squint for SVG to PNG conversion.


backers and sponsors chat version license build code style

Web function to generate PNGs from SVGs. Based on convert-svg-to-png which uses headless Chromium.

The proxy accepts a request for e.g. https://raster.example.com/example.png and translates it to a request for https://other-server.example.com/example.svg. If the path doesn't contain .png, it passes is unchanged, e.g. https://raster.example.com/example to https://other-server.example.com/example.

The query string is also forwarded upstream. Cache headers are forwarded downstream.

The host comes from the BASE_URL environment variable.

Designed for Shields though may be useful for other application as well.

Architecture

  • The code is is one file.
  • It's based on the Micro framework.
  • Rasterization uses headless Chromium via Puppeteer, wrapped in the convert-svg-to-png library.
  • The service has no state. It simply fetches corresponding SVG badges from the upstream service, rasterizes them, and forwards cache headers along with the response.
  • Caching the rasterized badges is handled by a downstream CDN.

Deployment

Runs on Zeit Now.

raster.shields.io production hosting

Staging: https://shields-raster-staging.now.sh/

Production: https://raster.shields.io/

raster.shields.io hosting is provided by:

Pull requests are deployed automatically. Staging is deployed automatically from master. Production is deployed manually for now.

For information about current deploys, see the Now dashboard. See production hosting for a list of maintainers with access.

raster.shields.io is configured in the Shields Cloudflare as a CNAME for alias.zeit.co with traffic configured not to pass through Cloudflare. That's because it's cached by Now's Smart CDN instead.

Production Deployment

To deploy, run now alias shields-raster-staging.now.sh raster.shields.io. This ships the current staging build to production.

To setup your environment to run now, you'll need to install the CLI, login, and switch to the Shields team.

npm i -g now
now login
now teams switch shields1

Support

If you're having problems with the service, you can post questions in the #support room in Discord and the main Shields repo.

Contributing

If you use and love Shields, we ask that you make a one-time $10 donation to Shields. You can also contribute monthly or sponsor at a higher level.

Contributions welcome! Feel free to open discussions on the main Shields repo and to open pull requests here.

The #contributing room in Discord is also a good place to discuss and ask questions.

License

This project is licensed under the MIT license.