From c6c7284e182f973ba4b2efdedc96085255851784 Mon Sep 17 00:00:00 2001 From: Alvalen Date: Wed, 6 Sep 2023 22:05:49 +0700 Subject: [PATCH] [fix] fix sitemap error --- app/sitemap.js | 11 ----------- generate-sitemap.js | 2 +- next.config.js | 13 +++++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 app/sitemap.js diff --git a/app/sitemap.js b/app/sitemap.js deleted file mode 100644 index 733e589..0000000 --- a/app/sitemap.js +++ /dev/null @@ -1,11 +0,0 @@ -import { createReadStream } from 'fs'; -import { ServerResponse } from 'http'; - -const sitemapHandler = async (_, res = ServerResponse) => { - const sitemap = createReadStream('./public/sitemap.xml.gz'); - res.setHeader('content-type', 'application/xml'); - res.setHeader('content-encoding', 'gzip'); - sitemap.pipe(res); -}; - -export default sitemapHandler; diff --git a/generate-sitemap.js b/generate-sitemap.js index b562b76..db0d666 100644 --- a/generate-sitemap.js +++ b/generate-sitemap.js @@ -12,7 +12,7 @@ async function generateSitemap() { sitemap.write({ url: "/", changefreq: "daily", priority: 1.0 }); sitemap.write({ url: "/about", changefreq: "daily", priority: 0.9 }); sitemap.write({ url: "/projects", changefreq: "daily", priority: 0.9 }); - sitemap.write({ url: "/projects/archive", changefreq: "daily", priority: 0.9 }); + sitemap.write({ url: "/projects/archive", changefreq: "daily", priority: 0.7 }); sitemap.end(); diff --git a/next.config.js b/next.config.js index 6a7bc68..8d000bd 100644 --- a/next.config.js +++ b/next.config.js @@ -3,4 +3,17 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({ }); module.exports = withBundleAnalyzer({ // your Next.js configuration + async headers() { + return [ + { + source: "/sitemap.xml.gz", + headers: [ + { + key: "Content-Type", + value: "application/gzip", + }, + ], + }, + ]; + }, });