【问题标题】:How to access sitemap.xml on public url in a react server rendered app如何在反应服务器呈现的应用程序中访问公共 url 上的 sitemap.xml
【发布时间】:2019-11-06 11:24:56
【问题描述】:

我正在开发一个使用服务器端渲染的反应应用程序,我想在访问 URL 时查看 sitemap.xml 文件的内容,例如本地主机:3000 /sitemap.xml。现在,我正在借助第三方库生成站点地图文件,并在 web 包完成构建后将其放置在公用文件夹中。

我的问题是我在 localhost:3000/sitemap.xml 找不到文件。但是,我可以看到由 web-pack 捆绑的其他文件,例如 localhost:3000/main.css 有效。我如何才能达到预期的结果。

站点地图生成器

import path from 'path'; //add path which will be needed for file write

const SitemapGenerator = require('sitemap-generator');

// create generator
const generator = SitemapGenerator('https://www.example.com', {
  stripQuerystring: false,
  filepath: path.resolve('./public', 'sitemap.xml')
});

// start the crawler
generator.start();

【问题讨论】:

    标签: javascript reactjs


    【解决方案1】:

    我通过将 xml 添加到我的服务器重写规则来解决。

    原来是</^((?!\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>

    更新为</^((?!\.(css|gif|ico|jpg|js|png|txt|svg|woff|xml|ttf)$).)*$/>

    【讨论】:

      猜你喜欢
      • 2019-07-18
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 2018-02-01
      • 2017-07-17
      • 2019-01-14
      • 2013-06-16
      • 1970-01-01
      相关资源
      最近更新 更多