CDN Icon Fetcher is a Node.js library that allows you to fetch resources from various CDN providers. It supports fetching icons, images, content, JavaScript, and JSON files from popular CDNs like Cloudflare, Fastly, KeyCDN, Akamai, Amazon CloudFront, and Gcore.
To install the package, use npm:
npm install cdn-icon-fetcher
To fetch a resource from a specified CDN, use the fetchCdnResource
function. This function requires the CDN provider, resource type, token, and base URL as parameters.
const { fetchCdnResource } = require("cdn-icon-fetcher");
fetchCdnResource(
"cloudflare",
"icon",
"your-token",
"https://your-base-url.com"
)
.then((data) => {
console.log("Resource data:", data);
})
.catch((error) => {
console.error("Error fetching resource:", error);
});
To fetch an icon from the CDN, use the fetchIcon
function. This function can be customized with a token, request options, and the number of retries.
const { fetchIcon } = require("cdn-icon-fetcher");
fetchIcon("your-icon-token")
.then(() => {
console.log("Icon fetched successfully");
})
.catch(() => {
console.error("Failed to fetch icon");
});
- cdnProvider: The CDN provider (e.g., 'cloudflare', 'fastly', 'keycdn', 'akamai', 'amazoncloudfront', 'gcore').
- resourceType: The type of resource to fetch (e.g., 'icon', 'image', 'content', 'js', 'json').
- token: The token or identifier for the resource.
- baseUrl: The base URL of the CDN.
- Returns: A promise that resolves with the resource data.
- token: The token for the icon to fetch.
- options: Options for the request, including the URL and headers.
- retries: The number of retries if the request fails.
- Returns: A promise that resolves when the icon data is fetched.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
- Added support for additional CDN providers.
- Improved error handling and retry logic.
- Updated documentation and examples.
For more information, please visit the GitHub repository.