Skip to content

Commit

Permalink
fix: Default host img.shields.io and remove formatted-dynamic-badges (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DenverCoder1 authored Nov 21, 2022
1 parent 2a02090 commit 71561f7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ You can set the `host` parameter to one of the following to override the hostnam

- [`img.shields.io`](https://img.shields.io)
- [`staging.shields.io`](https://staging.shields.io)
- [`formatted-dynamic-badges.herokuapp.com`](https://formatted-dynamic-badges.herokuapp.com)

If you would like to use a different badge host, fork and modify this repository. Create a PR if it may be useful to others.

Expand Down
9 changes: 3 additions & 6 deletions server/services/fetchBadges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ function buildQueryStringFromItem(

/**
* Validate hostname is allowed
* @param {string|null} host hostname to validate
* @param {string} host hostname to validate
* @returns {boolean} True if host is valid, otherwise false
*/
function isValidHost(host: string): boolean {
const validHosts = [
'img.shields.io',
'staging.shields.io',
'formatted-dynamic-badges.herokuapp.com',
];
return validHosts.includes(host);
}
Expand All @@ -89,10 +88,8 @@ function getBadgeUrl(
): string {
// build url using request params and query
const params = Object.values(req.params).map((p) => encodeURIComponent(p)).join('/');
const host = typeof req.query.host === 'string' ? req.query.host : 'img.shields.io';
if (!isValidHost(host)) {
throw new BadgeError('invalid host');
}
const userHost = req.query.host;
const host = typeof userHost === 'string' && isValidHost(userHost) ? userHost : 'img.shields.io';
const queryString = buildQueryStringFromItem(req, item);
return `https://${host}/${params}?${queryString}`;
}
Expand Down

0 comments on commit 71561f7

Please sign in to comment.