Elysia Tools
Navigation
Edge Computing
Netlify Edge local data exercises
Classify mock methods, choose demonstration locales and bound numeric cache durations locally without deploying an edge function.
Samples
Entries inside this sample collection
Classify a mock method label
Map three string labels to local display categories. This does not create a request, response, route or edge function.
function methodLabel(method) {
if (method === 'GET') return 'view';
if (method === 'HEAD') return 'metadata';
return 'unsupported';
}
const result = ['GET', 'HEAD', 'OTHER'].map(methodLabel);
console.log(JSON.stringify(result));Choose a demo locale
Accept only the two demonstration locale labels. An unknown label falls back to en, without reading headers, cookies or location.
function demoLocale(label) {
return new Set(['en', 'zh']).has(label) ? label : 'en';
}
const result = ['zh', 'other'].map(demoLocale);
console.log(JSON.stringify(result));Bound a mock cache duration
Clamp integer seconds to 0–60 and use zero for non-integers. This is only a number, not a deployed cache rule or header.
function cacheSeconds(value) {
return Number.isInteger(value) ? Math.max(0, Math.min(60, value)) : 0;
}
const result = [-1, 30, 100, 1.5].map(cacheSeconds);
console.log(JSON.stringify(result));Tools
Tools frequently paired with this sample
Related
Related sample collections
Related