Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How it works.. #811

Closed
techtonik opened this issue Oct 19, 2016 · 4 comments
Closed

How it works.. #811

techtonik opened this issue Oct 19, 2016 · 4 comments
Labels
documentation Developer and end-user documentation

Comments

@techtonik
Copy link
Contributor

I guess that badges are compiled dynamically on each request and then cached, but how it works in detail?

Assuming the auditory is somebody who wants to tackle #507 without much knowledge of JavaScript and supporting infrastructure.

For the start, https://img.shields.io/ runs a web server. Root request redirects to a https://shields.io/ domain with human instructions. Any other request to https://img.shields.io/ subpaths is handled by ? ... ? which parses URL parameters, ?checks status?, creates SVG and caches it.

How SVG is created?

@techtonik
Copy link
Contributor Author

Server is implemented with Camp.js, which takes a series of route callbacks that look like:

// Travis integration
camp.route(/^\/travis(-ci)?\/([^\/]+\/[^\/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
  var userRepo = match[2];  // eg, espadrine/sc
  var branch = match[3];
  var format = match[4];
  var options = {
    method: 'HEAD',
    uri: 'https://api.travis-ci.org/' + userRepo + '.svg',
  };
...

@techtonik
Copy link
Contributor Author

The data argument passed into callback is an object with URL query params, such as style etc. It is parsed by getBadgeData() function;

// data (URL query) can include `label`, `style`, `logo`, `logoWidth`, `link`.
// It can also include `maxAge`.
function getBadgeData(defaultLabel, data) {
  var label = getLabel(defaultLabel, data);
  var template = data.style || 'default';
...

@techtonik
Copy link
Contributor Author

Finally I found a place where logo data is passed from parsed query (data param) to shields function that returns cached and optimized SVG.

@paulmelnikow paulmelnikow added developer-experience Dev tooling, test framework, and CI and removed docs labels Apr 17, 2017
@paulmelnikow paulmelnikow added the core Server, BaseService, GitHub auth label Oct 13, 2017
@paulmelnikow paulmelnikow added documentation Developer and end-user documentation and removed core Server, BaseService, GitHub auth developer-experience Dev tooling, test framework, and CI labels Nov 6, 2018
@paulmelnikow
Copy link
Member

paulmelnikow commented Jan 8, 2019

The production hosting is documented in #2661 and the rest of this is for a legacy interface which we no longer use, so closing this.

Also opened #2684 asking for a high-level code walkthrough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Developer and end-user documentation
Projects
None yet
Development

No branches or pull requests

2 participants