authscape 1.0.735 → 1.0.737
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 +71 -36
- package/package.json +1 -1
- package/src/lib/sitemap-route.js +24 -6
- package/src/services/sitemapService.js +17 -5
package/index.js
CHANGED
|
@@ -8144,7 +8144,7 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
8144
8144
|
function createSitemapRoute(apiUri) {
|
|
8145
8145
|
return /*#__PURE__*/function () {
|
|
8146
8146
|
var _GET = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request) {
|
|
8147
|
-
var url, protocol, host, domain, encodedDomain, response, sitemap;
|
|
8147
|
+
var url, protocol, host, domain, encodedDomain, apiUrl, response, errorBody, sitemap;
|
|
8148
8148
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
8149
8149
|
while (1) switch (_context.prev = _context.next) {
|
|
8150
8150
|
case 0:
|
|
@@ -8152,11 +8152,14 @@ function createSitemapRoute(apiUri) {
|
|
|
8152
8152
|
// Get the domain from the request
|
|
8153
8153
|
url = new URL(request.url);
|
|
8154
8154
|
protocol = request.headers.get('x-forwarded-proto') || url.protocol.replace(':', '');
|
|
8155
|
-
host = request.headers.get('host') || url.host;
|
|
8156
|
-
|
|
8157
|
-
|
|
8155
|
+
host = request.headers.get('host') || url.host; // Determine protocol based on host
|
|
8156
|
+
if (host.includes("localhost")) {
|
|
8157
|
+
domain = "http://" + host;
|
|
8158
|
+
} else {
|
|
8159
|
+
domain = "https://" + host;
|
|
8160
|
+
}
|
|
8158
8161
|
if (apiUri) {
|
|
8159
|
-
_context.next =
|
|
8162
|
+
_context.next = 8;
|
|
8160
8163
|
break;
|
|
8161
8164
|
}
|
|
8162
8165
|
console.error('AuthScape Sitemap Error: apiUri is not configured in environment variables');
|
|
@@ -8166,21 +8169,37 @@ function createSitemapRoute(apiUri) {
|
|
|
8166
8169
|
'Content-Type': 'text/plain'
|
|
8167
8170
|
}
|
|
8168
8171
|
}));
|
|
8169
|
-
case
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8172
|
+
case 8:
|
|
8173
|
+
// URL encode the domain for the API request
|
|
8174
|
+
encodedDomain = encodeURIComponent(domain);
|
|
8175
|
+
apiUrl = "".concat(apiUri, "/api/Sitemap?domain=").concat(encodedDomain);
|
|
8176
|
+
console.log('Fetching sitemap from:', apiUrl);
|
|
8177
|
+
console.log('Domain being sent:', domain);
|
|
8178
|
+
console.log('Encoded domain:', encodedDomain);
|
|
8179
|
+
_context.next = 15;
|
|
8180
|
+
return fetch(apiUrl);
|
|
8181
|
+
case 15:
|
|
8173
8182
|
response = _context.sent;
|
|
8174
8183
|
if (response.ok) {
|
|
8175
|
-
_context.next =
|
|
8184
|
+
_context.next = 24;
|
|
8176
8185
|
break;
|
|
8177
8186
|
}
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
_context.next =
|
|
8187
|
+
console.error('API Response Status:', response.status);
|
|
8188
|
+
console.error('API Response StatusText:', response.statusText);
|
|
8189
|
+
_context.next = 21;
|
|
8181
8190
|
return response.text();
|
|
8182
|
-
case
|
|
8191
|
+
case 21:
|
|
8192
|
+
errorBody = _context.sent;
|
|
8193
|
+
console.error('API Response Body:', errorBody);
|
|
8194
|
+
throw new Error("API request failed with status ".concat(response.status, ": ").concat(errorBody));
|
|
8195
|
+
case 24:
|
|
8196
|
+
_context.next = 26;
|
|
8197
|
+
return response.text();
|
|
8198
|
+
case 26:
|
|
8183
8199
|
sitemap = _context.sent;
|
|
8200
|
+
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
8201
|
+
|
|
8202
|
+
// Return the XML response with appropriate headers
|
|
8184
8203
|
return _context.abrupt("return", new Response(sitemap, {
|
|
8185
8204
|
status: 200,
|
|
8186
8205
|
headers: {
|
|
@@ -8188,21 +8207,21 @@ function createSitemapRoute(apiUri) {
|
|
|
8188
8207
|
'Cache-Control': 'public, s-maxage=86400, stale-while-revalidate'
|
|
8189
8208
|
}
|
|
8190
8209
|
}));
|
|
8191
|
-
case
|
|
8192
|
-
_context.prev =
|
|
8210
|
+
case 31:
|
|
8211
|
+
_context.prev = 31;
|
|
8193
8212
|
_context.t0 = _context["catch"](0);
|
|
8194
8213
|
console.error('AuthScape Sitemap Error:', _context.t0);
|
|
8195
|
-
return _context.abrupt("return", new Response(
|
|
8214
|
+
return _context.abrupt("return", new Response("Error generating sitemap: ".concat(_context.t0.message || _context.t0), {
|
|
8196
8215
|
status: 500,
|
|
8197
8216
|
headers: {
|
|
8198
8217
|
'Content-Type': 'text/plain'
|
|
8199
8218
|
}
|
|
8200
8219
|
}));
|
|
8201
|
-
case
|
|
8220
|
+
case 35:
|
|
8202
8221
|
case "end":
|
|
8203
8222
|
return _context.stop();
|
|
8204
8223
|
}
|
|
8205
|
-
}, _callee, null, [[0,
|
|
8224
|
+
}, _callee, null, [[0, 31]]);
|
|
8206
8225
|
}));
|
|
8207
8226
|
function GET(_x) {
|
|
8208
8227
|
return _GET.apply(this, arguments);
|
|
@@ -9500,7 +9519,7 @@ function generateSitemap(_x, _x2, _x3) {
|
|
|
9500
9519
|
}
|
|
9501
9520
|
function _generateSitemap() {
|
|
9502
9521
|
_generateSitemap = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, apiUri) {
|
|
9503
|
-
var host, domain, encodedDomain, response, sitemap;
|
|
9522
|
+
var host, domain, encodedDomain, apiUrl, response, errorBody, sitemap;
|
|
9504
9523
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
9505
9524
|
while (1) switch (_context.prev = _context.next) {
|
|
9506
9525
|
case 0:
|
|
@@ -9514,37 +9533,53 @@ function _generateSitemap() {
|
|
|
9514
9533
|
}
|
|
9515
9534
|
|
|
9516
9535
|
// URL encode the domain for the API request
|
|
9517
|
-
encodedDomain = encodeURIComponent(domain);
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9536
|
+
encodedDomain = encodeURIComponent(domain);
|
|
9537
|
+
apiUrl = "".concat(apiUri, "/api/Sitemap?domain=").concat(encodedDomain);
|
|
9538
|
+
console.log('Fetching sitemap from:', apiUrl);
|
|
9539
|
+
console.log('Domain being sent:', domain);
|
|
9540
|
+
console.log('Encoded domain:', encodedDomain);
|
|
9541
|
+
|
|
9542
|
+
// Make a basic HTTP GET request to AuthScape API
|
|
9543
|
+
_context.next = 10;
|
|
9544
|
+
return fetch(apiUrl);
|
|
9545
|
+
case 10:
|
|
9521
9546
|
response = _context.sent;
|
|
9522
9547
|
if (response.ok) {
|
|
9523
|
-
_context.next =
|
|
9548
|
+
_context.next = 19;
|
|
9524
9549
|
break;
|
|
9525
9550
|
}
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
_context.next =
|
|
9551
|
+
console.error('API Response Status:', response.status);
|
|
9552
|
+
console.error('API Response StatusText:', response.statusText);
|
|
9553
|
+
_context.next = 16;
|
|
9529
9554
|
return response.text();
|
|
9530
|
-
case
|
|
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;
|
|
9561
|
+
return response.text();
|
|
9562
|
+
case 21:
|
|
9531
9563
|
sitemap = _context.sent;
|
|
9532
|
-
|
|
9564
|
+
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
9565
|
+
|
|
9566
|
+
// Set status code and headers BEFORE writing
|
|
9567
|
+
res.statusCode = 200;
|
|
9533
9568
|
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
|
|
9534
9569
|
res.setHeader('Cache-Control', 'public, s-maxage=86400, stale-while-revalidate');
|
|
9535
9570
|
|
|
9536
|
-
//
|
|
9571
|
+
// Write and end the response
|
|
9537
9572
|
res.write(sitemap);
|
|
9538
9573
|
res.end();
|
|
9539
9574
|
return _context.abrupt("return", {
|
|
9540
9575
|
props: {}
|
|
9541
9576
|
});
|
|
9542
|
-
case
|
|
9543
|
-
_context.prev =
|
|
9577
|
+
case 31:
|
|
9578
|
+
_context.prev = 31;
|
|
9544
9579
|
_context.t0 = _context["catch"](0);
|
|
9545
9580
|
console.error('AuthScape Sitemap Error:', _context.t0);
|
|
9546
9581
|
|
|
9547
|
-
//
|
|
9582
|
+
// Set status code BEFORE headers and writing
|
|
9548
9583
|
res.statusCode = 500;
|
|
9549
9584
|
res.setHeader('Content-Type', 'text/plain');
|
|
9550
9585
|
res.write("Error generating sitemap: ".concat(_context.t0.message || _context.t0));
|
|
@@ -9552,11 +9587,11 @@ function _generateSitemap() {
|
|
|
9552
9587
|
return _context.abrupt("return", {
|
|
9553
9588
|
props: {}
|
|
9554
9589
|
});
|
|
9555
|
-
case
|
|
9590
|
+
case 39:
|
|
9556
9591
|
case "end":
|
|
9557
9592
|
return _context.stop();
|
|
9558
9593
|
}
|
|
9559
|
-
}, _callee, null, [[0,
|
|
9594
|
+
}, _callee, null, [[0, 31]]);
|
|
9560
9595
|
}));
|
|
9561
9596
|
return _generateSitemap.apply(this, arguments);
|
|
9562
9597
|
}
|
package/package.json
CHANGED
package/src/lib/sitemap-route.js
CHANGED
|
@@ -16,10 +16,14 @@ export function createSitemapRoute(apiUri) {
|
|
|
16
16
|
const url = new URL(request.url);
|
|
17
17
|
const protocol = request.headers.get('x-forwarded-proto') || url.protocol.replace(':', '');
|
|
18
18
|
const host = request.headers.get('host') || url.host;
|
|
19
|
-
const domain = `${protocol}://${host}`;
|
|
20
19
|
|
|
21
|
-
//
|
|
22
|
-
|
|
20
|
+
// Determine protocol based on host
|
|
21
|
+
let domain;
|
|
22
|
+
if (host.includes("localhost")) {
|
|
23
|
+
domain = "http://" + host;
|
|
24
|
+
} else {
|
|
25
|
+
domain = "https://" + host;
|
|
26
|
+
}
|
|
23
27
|
|
|
24
28
|
if (!apiUri) {
|
|
25
29
|
console.error('AuthScape Sitemap Error: apiUri is not configured in environment variables');
|
|
@@ -31,15 +35,29 @@ export function createSitemapRoute(apiUri) {
|
|
|
31
35
|
});
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
// URL encode the domain for the API request
|
|
39
|
+
const encodedDomain = encodeURIComponent(domain);
|
|
40
|
+
const apiUrl = `${apiUri}/api/Sitemap?domain=${encodedDomain}`;
|
|
41
|
+
|
|
42
|
+
console.log('Fetching sitemap from:', apiUrl);
|
|
43
|
+
console.log('Domain being sent:', domain);
|
|
44
|
+
console.log('Encoded domain:', encodedDomain);
|
|
45
|
+
|
|
46
|
+
const response = await fetch(apiUrl);
|
|
35
47
|
|
|
36
48
|
if (!response.ok) {
|
|
37
|
-
|
|
49
|
+
console.error('API Response Status:', response.status);
|
|
50
|
+
console.error('API Response StatusText:', response.statusText);
|
|
51
|
+
const errorBody = await response.text();
|
|
52
|
+
console.error('API Response Body:', errorBody);
|
|
53
|
+
throw new Error(`API request failed with status ${response.status}: ${errorBody}`);
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
// Get the sitemap XML
|
|
41
57
|
const sitemap = await response.text();
|
|
42
58
|
|
|
59
|
+
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
60
|
+
|
|
43
61
|
// Return the XML response with appropriate headers
|
|
44
62
|
return new Response(sitemap, {
|
|
45
63
|
status: 200,
|
|
@@ -51,7 +69,7 @@ export function createSitemapRoute(apiUri) {
|
|
|
51
69
|
} catch (error) {
|
|
52
70
|
console.error('AuthScape Sitemap Error:', error);
|
|
53
71
|
|
|
54
|
-
return new Response(
|
|
72
|
+
return new Response(`Error generating sitemap: ${error.message || error}`, {
|
|
55
73
|
status: 500,
|
|
56
74
|
headers: {
|
|
57
75
|
'Content-Type': 'text/plain',
|
|
@@ -25,22 +25,34 @@ export async function generateSitemap(req, res, apiUri) {
|
|
|
25
25
|
|
|
26
26
|
// URL encode the domain for the API request
|
|
27
27
|
const encodedDomain = encodeURIComponent(domain);
|
|
28
|
+
const apiUrl = `${apiUri}/api/Sitemap?domain=${encodedDomain}`;
|
|
29
|
+
|
|
30
|
+
console.log('Fetching sitemap from:', apiUrl);
|
|
31
|
+
console.log('Domain being sent:', domain);
|
|
32
|
+
console.log('Encoded domain:', encodedDomain);
|
|
28
33
|
|
|
29
34
|
// Make a basic HTTP GET request to AuthScape API
|
|
30
|
-
const response = await fetch(
|
|
35
|
+
const response = await fetch(apiUrl);
|
|
31
36
|
|
|
32
37
|
if (!response.ok) {
|
|
33
|
-
|
|
38
|
+
console.error('API Response Status:', response.status);
|
|
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}`);
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
// Get the sitemap XML from the API
|
|
37
46
|
const sitemap = await response.text();
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
49
|
+
|
|
50
|
+
// Set status code and headers BEFORE writing
|
|
51
|
+
res.statusCode = 200;
|
|
40
52
|
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
|
|
41
53
|
res.setHeader('Cache-Control', 'public, s-maxage=86400, stale-while-revalidate');
|
|
42
54
|
|
|
43
|
-
//
|
|
55
|
+
// Write and end the response
|
|
44
56
|
res.write(sitemap);
|
|
45
57
|
res.end();
|
|
46
58
|
|
|
@@ -50,7 +62,7 @@ export async function generateSitemap(req, res, apiUri) {
|
|
|
50
62
|
} catch (error) {
|
|
51
63
|
console.error('AuthScape Sitemap Error:', error);
|
|
52
64
|
|
|
53
|
-
//
|
|
65
|
+
// Set status code BEFORE headers and writing
|
|
54
66
|
res.statusCode = 500;
|
|
55
67
|
res.setHeader('Content-Type', 'text/plain');
|
|
56
68
|
res.write(`Error generating sitemap: ${error.message || error}`);
|