authscape 1.0.737 → 1.0.738
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.
- package/index.js +16 -36
- package/package.json +1 -1
- package/src/scripts/postinstall.js +7 -6
- package/src/services/sitemapService.js +2 -21
package/index.js
CHANGED
|
@@ -9519,51 +9519,37 @@ function generateSitemap(_x, _x2, _x3) {
|
|
|
9519
9519
|
}
|
|
9520
9520
|
function _generateSitemap() {
|
|
9521
9521
|
_generateSitemap = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, apiUri) {
|
|
9522
|
-
var host, domain, encodedDomain, apiUrl, response,
|
|
9522
|
+
var host, domain, encodedDomain, apiUrl, response, sitemap;
|
|
9523
9523
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
9524
9524
|
while (1) switch (_context.prev = _context.next) {
|
|
9525
9525
|
case 0:
|
|
9526
9526
|
_context.prev = 0;
|
|
9527
|
-
|
|
9528
|
-
host = req.headers.host; // Determine protocol - same logic as PrivateLabelPageModule
|
|
9527
|
+
host = req.headers.host;
|
|
9529
9528
|
if (host.includes("localhost")) {
|
|
9530
9529
|
domain = "http://" + host;
|
|
9531
9530
|
} else {
|
|
9532
9531
|
domain = "https://" + host;
|
|
9533
9532
|
}
|
|
9534
|
-
|
|
9535
|
-
// URL encode the domain for the API request
|
|
9536
9533
|
encodedDomain = encodeURIComponent(domain);
|
|
9537
9534
|
apiUrl = "".concat(apiUri, "/api/Sitemap?domain=").concat(encodedDomain);
|
|
9538
9535
|
console.log('Fetching sitemap from:', apiUrl);
|
|
9539
|
-
|
|
9540
|
-
console.log('Encoded domain:', encodedDomain);
|
|
9541
|
-
|
|
9542
|
-
// Make a basic HTTP GET request to AuthScape API
|
|
9543
|
-
_context.next = 10;
|
|
9536
|
+
_context.next = 8;
|
|
9544
9537
|
return fetch(apiUrl);
|
|
9545
|
-
case
|
|
9538
|
+
case 8:
|
|
9546
9539
|
response = _context.sent;
|
|
9547
9540
|
if (response.ok) {
|
|
9548
|
-
_context.next =
|
|
9541
|
+
_context.next = 11;
|
|
9549
9542
|
break;
|
|
9550
9543
|
}
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
_context.next =
|
|
9554
|
-
return response.text();
|
|
9555
|
-
case 16:
|
|
9556
|
-
errorBody = _context.sent;
|
|
9557
|
-
console.error('API Response Body:', errorBody);
|
|
9558
|
-
throw new Error("API request failed with status ".concat(response.status, ": ").concat(errorBody));
|
|
9559
|
-
case 19:
|
|
9560
|
-
_context.next = 21;
|
|
9544
|
+
throw new Error("API request failed with status ".concat(response.status));
|
|
9545
|
+
case 11:
|
|
9546
|
+
_context.next = 13;
|
|
9561
9547
|
return response.text();
|
|
9562
|
-
case
|
|
9548
|
+
case 13:
|
|
9563
9549
|
sitemap = _context.sent;
|
|
9564
9550
|
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
9565
9551
|
|
|
9566
|
-
// Set
|
|
9552
|
+
// Set headers BEFORE writing
|
|
9567
9553
|
res.statusCode = 200;
|
|
9568
9554
|
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
|
|
9569
9555
|
res.setHeader('Cache-Control', 'public, s-maxage=86400, stale-while-revalidate');
|
|
@@ -9571,27 +9557,21 @@ function _generateSitemap() {
|
|
|
9571
9557
|
// Write and end the response
|
|
9572
9558
|
res.write(sitemap);
|
|
9573
9559
|
res.end();
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
_context.prev = 31;
|
|
9560
|
+
_context.next = 29;
|
|
9561
|
+
break;
|
|
9562
|
+
case 22:
|
|
9563
|
+
_context.prev = 22;
|
|
9579
9564
|
_context.t0 = _context["catch"](0);
|
|
9580
9565
|
console.error('AuthScape Sitemap Error:', _context.t0);
|
|
9581
|
-
|
|
9582
|
-
// Set status code BEFORE headers and writing
|
|
9583
9566
|
res.statusCode = 500;
|
|
9584
9567
|
res.setHeader('Content-Type', 'text/plain');
|
|
9585
9568
|
res.write("Error generating sitemap: ".concat(_context.t0.message || _context.t0));
|
|
9586
9569
|
res.end();
|
|
9587
|
-
|
|
9588
|
-
props: {}
|
|
9589
|
-
});
|
|
9590
|
-
case 39:
|
|
9570
|
+
case 29:
|
|
9591
9571
|
case "end":
|
|
9592
9572
|
return _context.stop();
|
|
9593
9573
|
}
|
|
9594
|
-
}, _callee, null, [[0,
|
|
9574
|
+
}, _callee, null, [[0, 22]]);
|
|
9595
9575
|
}));
|
|
9596
9576
|
return _generateSitemap.apply(this, arguments);
|
|
9597
9577
|
}
|
package/package.json
CHANGED
|
@@ -12,11 +12,6 @@ const path = require('path');
|
|
|
12
12
|
const PAGES_ROUTER_TEMPLATE = `// Auto-generated by AuthScape - Do not edit manually
|
|
13
13
|
import { generateSitemap } from 'authscape/src/services/sitemapService';
|
|
14
14
|
|
|
15
|
-
export default function Sitemap() {
|
|
16
|
-
// This page is handled by getServerSideProps
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
15
|
export async function getServerSideProps({ req, res }) {
|
|
21
16
|
const apiBaseUri = process.env.apiUri;
|
|
22
17
|
|
|
@@ -29,7 +24,13 @@ export async function getServerSideProps({ req, res }) {
|
|
|
29
24
|
return { props: {} };
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
await generateSitemap(req, res, apiBaseUri);
|
|
28
|
+
|
|
29
|
+
return { props: {} };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default function Sitemap() {
|
|
33
|
+
return null;
|
|
33
34
|
}
|
|
34
35
|
`;
|
|
35
36
|
|
|
@@ -12,10 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export async function generateSitemap(req, res, apiUri) {
|
|
14
14
|
try {
|
|
15
|
-
// Get the domain from the request
|
|
16
15
|
const host = req.headers.host;
|
|
17
16
|
|
|
18
|
-
// Determine protocol - same logic as PrivateLabelPageModule
|
|
19
17
|
let domain;
|
|
20
18
|
if (host.includes("localhost")) {
|
|
21
19
|
domain = "http://" + host;
|
|
@@ -23,31 +21,22 @@ export async function generateSitemap(req, res, apiUri) {
|
|
|
23
21
|
domain = "https://" + host;
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
// URL encode the domain for the API request
|
|
27
24
|
const encodedDomain = encodeURIComponent(domain);
|
|
28
25
|
const apiUrl = `${apiUri}/api/Sitemap?domain=${encodedDomain}`;
|
|
29
26
|
|
|
30
27
|
console.log('Fetching sitemap from:', apiUrl);
|
|
31
|
-
console.log('Domain being sent:', domain);
|
|
32
|
-
console.log('Encoded domain:', encodedDomain);
|
|
33
28
|
|
|
34
|
-
// Make a basic HTTP GET request to AuthScape API
|
|
35
29
|
const response = await fetch(apiUrl);
|
|
36
30
|
|
|
37
31
|
if (!response.ok) {
|
|
38
|
-
|
|
39
|
-
console.error('API Response StatusText:', response.statusText);
|
|
40
|
-
const errorBody = await response.text();
|
|
41
|
-
console.error('API Response Body:', errorBody);
|
|
42
|
-
throw new Error(`API request failed with status ${response.status}: ${errorBody}`);
|
|
32
|
+
throw new Error(`API request failed with status ${response.status}`);
|
|
43
33
|
}
|
|
44
34
|
|
|
45
|
-
// Get the sitemap XML from the API
|
|
46
35
|
const sitemap = await response.text();
|
|
47
36
|
|
|
48
37
|
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
49
38
|
|
|
50
|
-
// Set
|
|
39
|
+
// Set headers BEFORE writing
|
|
51
40
|
res.statusCode = 200;
|
|
52
41
|
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
|
|
53
42
|
res.setHeader('Cache-Control', 'public, s-maxage=86400, stale-while-revalidate');
|
|
@@ -56,21 +45,13 @@ export async function generateSitemap(req, res, apiUri) {
|
|
|
56
45
|
res.write(sitemap);
|
|
57
46
|
res.end();
|
|
58
47
|
|
|
59
|
-
return {
|
|
60
|
-
props: {},
|
|
61
|
-
};
|
|
62
48
|
} catch (error) {
|
|
63
49
|
console.error('AuthScape Sitemap Error:', error);
|
|
64
50
|
|
|
65
|
-
// Set status code BEFORE headers and writing
|
|
66
51
|
res.statusCode = 500;
|
|
67
52
|
res.setHeader('Content-Type', 'text/plain');
|
|
68
53
|
res.write(`Error generating sitemap: ${error.message || error}`);
|
|
69
54
|
res.end();
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
props: {},
|
|
73
|
-
};
|
|
74
55
|
}
|
|
75
56
|
}
|
|
76
57
|
|