代码之家  ›  专栏  ›  技术社区  ›  Jean DuPont

节点。js:为虚拟主机使用站点地图(vhost)

  •  0
  • Jean DuPont  · 技术社区  · 10 年前

    我是node.js的初学者。 目前我正在使用节点。js+快递+ vhost 托管不同的域,如 http://example1.com , http://example2.io 等

    如何为每个域提供不同的站点地图( http://example1.com/sitemap.xml , http://example2.io/sitemap.xml ) ?

    我看到这个站点地图生成框架: sitemap 这实际上并不坏,但我不知道如何在虚拟主机上使用它。

    机器人也面临同样的问题。每个域的txt文件。

    1 回复  |  直到 10 年前
        1
  •  1
  •   Jean DuPont    10 年前

    好的,我明白了。 sitemap.js 达到理想的结果 我的代码:

    const sm = require('sitemap');
    const sitemap = sm.createSitemap({
        hostname: 'http://' + req.vhost.host,
        cacheTime: 600000
    });
    sitemap.add({
        url: '/page1',
        changefreq: 'weekly',
        priority: 1.0
    });
    
    res.header('Content-Type', 'application/xml');
    res.send(sitemap.toString());
    
    推荐文章