我正在使用几个路由器文件在网站不同章节上的快速服务器上工作。最后,现有的哈巴狗页面不会有太大变化,但是在过渡期间,会有一些动态内容,主要是说“此页面尚未迁移(翻译),请参阅旧版本……”。
每章的页面数是给定的或非常缓慢地增加。因此,我列出了来自网站的允许请求以提供答案,此外还包含默认响应。
我做了几个变体,所有的变体都奏效,但是我问是否有一个或全部会引起内存问题,如果同时有很多需求。如果是这样,什么是好的做法?
我尝试使用字符串数组作为文件名,其中我仅具有文件名,还尝试使用对象数组,其中我具有文件名和临时内容。 路由器从请求中提取文件名,并将其与变量进行比较。如果存在,它将提供或创建该文件。
//Version array. (Past and future refer to the chronological order
// of the events allow to flip through the archive's years with an
//arrow on the pug page. They are defined by the index of the
//filename in the array)
var targets=['2019-1','2018-1'];
var current=targets[0];
router.get('/*',function(req,res) {
// get the name of the archive page from the link clicked
var event = (req.params[0]);
if( targets.includes(event) ) {
res.render('archive/'+event, {
title:'xyzzy - event in 20'+event,
message: 'page '+event+' coming soon ',
event:event ,
past: targets[targets.indexOf(event)+1],
future: targets[targets.indexOf(event)-1] || current
});
} else {
res.render('archive/'+current,
{title:'xyzzy - Events',
message: 'no event for '+event+ '.' });
}
});
//Second version: several arrays of objects, one per language
var etargets=[{c:'englishname',t:'englishtitle'}]
router.get('/*', function(req,res,next){
const cible = (req.params[0]);
var target = {t:'default title'}
var route='default'
...
if (etargets.find( ({c}) => c ===cible) ){
target = etargets.find( ({c}) => c ===cible);
route='e-asso/'+'cible';
...
}
...
res.render(route,{title:target.t ||'rien'});
})
寻找有关存储列表的最佳做法和最佳版本的建议。路由器功能内的数组数组,对象对象...