freetyy
freetyy

Reputation: 109

How to access sitemap.xml on public url in a react server rendered app

I am working on a react app that uses server side rendering and I want to view contents of a sitemap.xml file when i visit a URL e.g. localhost:3000 /sitemap.xml. Right now I am generating the sitemap file with help of a third party library and placing it in public folder after the web pack has finished building.

The problem i have is I can't find the file at localhost:3000/sitemap.xml. I can however see the other files that where bundled by web-pack for example localhost:3000/main.css works. How do i go about achieving the desired result.

sitemap generator

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();

Upvotes: 2

Views: 1385

Answers (1)

Dylan w
Dylan w

Reputation: 2906

I resolved by adding xml to my server rewrite rule.

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

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

Upvotes: 1

Related Questions