Uploadcare CNAME Prefix
This package provides a helper for working with Uploadcare CDN CNAME prefixes.
Install
npm install @uploadcare/cname-prefix
Usage
The package builds a subdomain-based (prefixed) CDN base from your public key. Two variants are available with identical output:
getPrefixedCdnBaseAsyncuses the Web Crypto API (window.crypto.subtle), returns a Promise, and works in browsers in a secure context (HTTPS orlocalhost). It is not available in Node.js or non-secure contexts.getPrefixedCdnBaseSyncships its own SHA-256, runs synchronously, and works anywhere: browsers (any context), Node.js, web workers, and edge runtimes.
import { getPrefixedCdnBaseAsync, getPrefixedCdnBaseSync } from '@uploadcare/cname-prefix'
await getPrefixedCdnBaseAsync('demopublickey', 'https://ucarecd.net')
// 'https://1s4oyld5dc.ucarecd.net'
getPrefixedCdnBaseSync('demopublickey', 'https://ucarecd.net')
// 'https://1s4oyld5dc.ucarecd.net'
Import from @uploadcare/cname-prefix/async or /sync to include just one
variant. Use isPrefixedCdnBase(cdnBase, base) to check whether a CDN base is
already prefixed.
Security issues
If you think you ran into something in Uploadcare libraries that might have security implications, please hit us up at bugbounty@uploadcare.com or Hackerone.
We'll contact you personally in a short time to fix an issue through co-op and prior to any public disclosure.
Feedback
Issues and PRs are welcome. You can provide your feedback or drop us a support request at hello@uploadcare.com.