Elysia Tools
导航
边缘计算
Netlify Edge 本地数据练习
本地分类模拟方法、选择演示语言并限制缓存数字时长,不部署边缘函数。
案例
这个案例集合中的条目
分类模拟方法标签
把三个字符串标签映射到本地展示类别;不创建请求、响应、路由或边缘函数。
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));选择演示语言
仅接受两个演示语言标签,未知值回退 en;不读取标头、Cookie 或位置。
function demoLocale(label) {
return new Set(['en', 'zh']).has(label) ? label : 'en';
}
const result = ['zh', 'other'].map(demoLocale);
console.log(JSON.stringify(result));限制模拟缓存时长
整数秒限制为 0–60,非整数取零;只是数字,不是已部署缓存规则或标头。
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));工具
经常与该案例搭配使用的工具
相关内容
相关案例集合
相关内容