rsnext/examples/with-sitemap-and-robots-express-server
Oleg Filonchuk aa6991f206 update readme.md (#10136)
fixed a little typo
2020-01-17 14:22:40 -05:00
..
pages Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
public Add docs to public (#7239) 2019-05-06 15:42:54 +02:00
server Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
.gitignore sitemap.xml and robots.txt example (#4163) 2018-05-25 14:01:32 +02:00
.npmignore sitemap.xml and robots.txt example (#4163) 2018-05-25 14:01:32 +02:00
now.json Move syntax formatting to prettier (#7454) 2019-05-29 13:57:26 +02:00
package.json Switch all examples to next@latest (#7806) 2019-07-08 18:41:33 -04:00
README.md update readme.md (#10136) 2020-01-17 14:22:40 -05:00

Example with sitemap.xml and robots.txt using Express server

This example app shows you how to set up sitemap.xml and robots.txt files for proper indexing by search engine bots.

The app is deployed at: https://sitemap-robots.now.sh. Open the page and click the links to see sitemap.xml and robots.txt. Here is a snapshot of these files, with sitemap.xml on the left and robots.txt on the right: sitemap-robots

How to use

Using create-next-app

Execute create-next-app with npm or Yarn to bootstrap the example:

npm init next-app --example with-sitemap-and-robots-express-server with-sitemap-and-robots-express-server-app
# or
yarn create next-app --example with-sitemap-and-robots-express-server with-sitemap-and-robots-express-server-app

Download manually

Download the example:

curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-sitemap-and-robots-express-server
cd with-sitemap-and-robots-express-server

Install it and run:

npm install
npm run start
# or
yarn
yarn start

Deploy it to the cloud with now (download)

now

Notes

  • routes /a and /b are added to sitemap manually
  • routes that start with /posts are added automatically to sitemap; the current example creates an array of posts (see server/posts.js), but in a production-level web app, you would want to update sitemap.xml dynamically by getting posts from a database:
    • see this app in which posts are fetched from a database

When you start this example locally:

In case you want to deploy this example, replace the URL in the following locations with your own domain:

  • hostname in server/sitemap.js
  • ROOT_URL in server/app.js
  • Sitemap at the bottom of robots.txt
  • alias in now.json

Deploy with now or with yarn now if you specified alias in now.json