Javascript 如何在react服务器呈现的应用程序中访问公共url上的sitemap.xml
我正在开发一个使用服务器端渲染的react应用程序,我想在访问URL(例如localhost:3000/sitemap.xml)时查看sitemap.xml文件的内容。现在,我正在第三方库的帮助下生成站点地图文件,并在web包构建完成后将其放置在公用文件夹中 我的问题是在localhost:3000/sitemap.xml上找不到该文件。但是,我可以看到web包捆绑的其他文件,例如localhost:3000/main.css。我怎样才能达到预期的结果呢 站点地图生成器Javascript 如何在react服务器呈现的应用程序中访问公共url上的sitemap.xml,javascript,reactjs,Javascript,Reactjs,我正在开发一个使用服务器端渲染的react应用程序,我想在访问URL(例如localhost:3000/sitemap.xml)时查看sitemap.xml文件的内容。现在,我正在第三方库的帮助下生成站点地图文件,并在web包构建完成后将其放置在公用文件夹中 我的问题是在localhost:3000/sitemap.xml上找不到该文件。但是,我可以看到web包捆绑的其他文件,例如localhost:3000/main.css。我怎样才能达到预期的结果呢 站点地图生成器 import path
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();
我通过将xml添加到服务器重写规则中解决了这个问题 它是
更新至