Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

9 Commits

Repository files navigation

CDN

Cache Dango Web Solutions CMS data and built-in Soar CDN assets in your Node.js web app as JSON.

Requirements

  • Must be using Node.js v10.12 or higher.

Usage

Include the @dangoweb/cdn package in your Express.js application:

constCDN=require('@dangoweb/cdn');constcdn=newCDN({dir: './cdn/',extension: '.cdn.json',ttl: 3600,});asyncfunctioncmsdata(){// Example fetching and caching CMS dataif(cdn.valid('cms'))returncdn.get('cms');// Return cached CMS data if validtry{returnawaitfetch(`...`,{})// Given fetch function to fetch CMS data from Dango Web Solutions.then(res=>res.json()).then(res=>{varcmsData=JSON.parse(JSON.stringify(res.data).replaceAll('.spaces','clients'));console.log('Writing...');cdn.cache('cms',cmsData);// Cache the CMS datareturncmsData;});}catch{try{returncdn.get('cms');// Fall back to cached CMS data}catch{console.error('Failed to fetch CMS data and no cached data found.');returnnull;};};};asyncfunctionstartApp(){varcms=awaitcmsdata();console.log(cms);};startApp();

Tests

Run tests using Jest:

npm test

Credits

Original developed by Komrod/local-cache

About

Cache Dango Web Solutions CMS data and built-in Soar CDN assets in your Node.js web app as JSON.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages