File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # CDN
2+
3+ Cache Dango Web Solutions CMS data and built-in Soar CDN assets in your Node.js web app as JSON.
4+
5+ ## Requirements
6+
7+ - Must be using Node.js v10.12 or higher.
8+
9+ ## Usage
10+
11+ Include the ` @dangoweb/cdn ` package in your Express.js application:
12+
13+ ``` javascript
14+ const CDN = require (' @dangoweb/cdn' );
15+ const cdn = new CDN ({
16+ dir: ' ./cdn/' ,
17+ extension: ' .cdn.json' ,
18+ ttl: 3600 ,
19+ });
20+
21+ async function cmsdata () { // Example fetching and caching CMS data
22+ if (cdn .valid (' cms' )) return cdn .get (' cms' ); // Return cached CMS data if valid
23+ try {
24+ return await fetch (` ...` , { }) // Given fetch function to fetch CMS data from Dango Web Solutions
25+ .then (res => res .json ())
26+ .then (res => {
27+ var cmsData = JSON .parse (JSON .stringify (res .data ).replaceAll (' .spaces' , ' clients' ));
28+ console .log (' Writing...' );
29+ cdn .cache (' cms' , cmsData); // Cache the CMS data
30+ return cmsData;
31+ });
32+ } catch {
33+ try {
34+ return cdn .get (' cms' ); // Fall back to cached CMS data
35+ } catch {
36+ console .error (' Failed to fetch CMS data and no cached data found.' );
37+ return null ;
38+ };
39+ };
40+ };
41+
42+ async function startApp () {
43+ var cms = await cmsdata ();
44+ console .log (cms);
45+ };
46+
47+ startApp ();
48+ ```
49+
50+ ## Tests
51+
52+ Run tests using Jest:
53+
54+ ``` bash
55+ npm test
56+ ```
57+
58+ ## Credits
59+
60+ Original developed by [ Komrod/local-cache] ( https://github.com/Komrod/local-cache )
You can’t perform that action at this time.
0 commit comments