create-sitecore-jss 22.5.0-canary.4 → 22.5.0-canary.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import type { NextApiRequest, NextApiResponse } from 'next';
2
- import { NativeDataFetcher, GraphQLSitemapXmlService } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import { NativeDataFetcher, GraphQLSitemapXmlService } from '@sitecore-jss/sitecore-jss-nextjs'
3
3
  import { siteResolver } from 'lib/site-resolver';
4
4
  import config from 'temp/config';
5
5
  import clientFactory from 'lib/graphql-client-factory';
@@ -24,11 +24,10 @@ const sitemapApi = async (
24
24
  siteName: site.name,
25
25
  });
26
26
 
27
- // The id is present if url has sitemap-{n}.xml type.
28
- // The id can be null if it's index sitemap.xml request
27
+ // if url has sitemap-{n}.xml type. The id - can be null if it's sitemap.xml request
29
28
  const sitemapPath = await sitemapXmlService.getSitemap(id as string);
30
29
 
31
- // regular sitemap
30
+ // if sitemap is match otherwise redirect to 404 page
32
31
  if (sitemapPath) {
33
32
  const isAbsoluteUrl = sitemapPath.match(ABSOLUTE_URL_REGEXP);
34
33
  const sitemapUrl = isAbsoluteUrl ? sitemapPath : `${config.sitecoreApiHost}${sitemapPath}`;
@@ -36,27 +35,18 @@ const sitemapApi = async (
36
35
 
37
36
  try {
38
37
  const fetcher = new NativeDataFetcher();
39
- const response = await fetcher.fetch<ReadableStream<Uint8Array>>(sitemapUrl);
38
+ const xmlResponse = await fetcher.fetch<string>(sitemapUrl);
40
39
 
41
- const reader = response.data.getReader();
42
- if (reader) {
43
- while (true) {
44
- const { done, value } = await reader.read();
45
-
46
- if (done) break;
47
- if (value) res.write(value);
48
- }
49
- }
50
-
51
- res.end();
40
+ return res.send(xmlResponse.data);
52
41
  } catch (error) {
53
42
  return res.redirect('/404');
54
43
  }
55
-
56
- return;
57
44
  }
58
45
 
59
- // index /sitemap.xml that includes links to all sitemaps
46
+
47
+
48
+
49
+ // this approache if user go to /sitemap.xml - under it generate xml page with list of sitemaps
60
50
  const sitemaps = await sitemapXmlService.fetchSitemaps();
61
51
 
62
52
  if (!sitemaps.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sitecore-jss",
3
- "version": "22.5.0-canary.4",
3
+ "version": "22.5.0-canary.6",
4
4
  "description": "Sitecore JSS initializer",
5
5
  "bin": "./dist/index.js",
6
6
  "scripts": {
@@ -65,5 +65,5 @@
65
65
  "ts-node": "^10.9.1",
66
66
  "typescript": "~5.6.3"
67
67
  },
68
- "gitHead": "9b0b19aaeb6c756fee9c1a603cb875120d285d3a"
68
+ "gitHead": "9ab8148977a555bd0a17a5606bf30feee155c294"
69
69
  }