authscape 1.0.735 → 1.0.736
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 +51 -34
- package/package.json +1 -1
- package/src/lib/sitemap-route.js +17 -5
- package/src/services/sitemapService.js +10 -4
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, 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,28 @@ 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
|
+
_context.next = 13;
|
|
8178
|
+
return fetch(apiUrl);
|
|
8179
|
+
case 13:
|
|
8173
8180
|
response = _context.sent;
|
|
8174
8181
|
if (response.ok) {
|
|
8175
|
-
_context.next =
|
|
8182
|
+
_context.next = 16;
|
|
8176
8183
|
break;
|
|
8177
8184
|
}
|
|
8178
8185
|
throw new Error("API request failed with status ".concat(response.status));
|
|
8179
|
-
case 14:
|
|
8180
|
-
_context.next = 16;
|
|
8181
|
-
return response.text();
|
|
8182
8186
|
case 16:
|
|
8187
|
+
_context.next = 18;
|
|
8188
|
+
return response.text();
|
|
8189
|
+
case 18:
|
|
8183
8190
|
sitemap = _context.sent;
|
|
8191
|
+
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
8192
|
+
|
|
8193
|
+
// Return the XML response with appropriate headers
|
|
8184
8194
|
return _context.abrupt("return", new Response(sitemap, {
|
|
8185
8195
|
status: 200,
|
|
8186
8196
|
headers: {
|
|
@@ -8188,21 +8198,21 @@ function createSitemapRoute(apiUri) {
|
|
|
8188
8198
|
'Cache-Control': 'public, s-maxage=86400, stale-while-revalidate'
|
|
8189
8199
|
}
|
|
8190
8200
|
}));
|
|
8191
|
-
case
|
|
8192
|
-
_context.prev =
|
|
8201
|
+
case 23:
|
|
8202
|
+
_context.prev = 23;
|
|
8193
8203
|
_context.t0 = _context["catch"](0);
|
|
8194
8204
|
console.error('AuthScape Sitemap Error:', _context.t0);
|
|
8195
|
-
return _context.abrupt("return", new Response(
|
|
8205
|
+
return _context.abrupt("return", new Response("Error generating sitemap: ".concat(_context.t0.message || _context.t0), {
|
|
8196
8206
|
status: 500,
|
|
8197
8207
|
headers: {
|
|
8198
8208
|
'Content-Type': 'text/plain'
|
|
8199
8209
|
}
|
|
8200
8210
|
}));
|
|
8201
|
-
case
|
|
8211
|
+
case 27:
|
|
8202
8212
|
case "end":
|
|
8203
8213
|
return _context.stop();
|
|
8204
8214
|
}
|
|
8205
|
-
}, _callee, null, [[0,
|
|
8215
|
+
}, _callee, null, [[0, 23]]);
|
|
8206
8216
|
}));
|
|
8207
8217
|
function GET(_x) {
|
|
8208
8218
|
return _GET.apply(this, arguments);
|
|
@@ -9500,7 +9510,7 @@ function generateSitemap(_x, _x2, _x3) {
|
|
|
9500
9510
|
}
|
|
9501
9511
|
function _generateSitemap() {
|
|
9502
9512
|
_generateSitemap = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, apiUri) {
|
|
9503
|
-
var host, domain, encodedDomain, response, sitemap;
|
|
9513
|
+
var host, domain, encodedDomain, apiUrl, response, sitemap;
|
|
9504
9514
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
9505
9515
|
while (1) switch (_context.prev = _context.next) {
|
|
9506
9516
|
case 0:
|
|
@@ -9514,37 +9524,44 @@ function _generateSitemap() {
|
|
|
9514
9524
|
}
|
|
9515
9525
|
|
|
9516
9526
|
// URL encode the domain for the API request
|
|
9517
|
-
encodedDomain = encodeURIComponent(domain);
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9527
|
+
encodedDomain = encodeURIComponent(domain);
|
|
9528
|
+
apiUrl = "".concat(apiUri, "/api/Sitemap?domain=").concat(encodedDomain);
|
|
9529
|
+
console.log('Fetching sitemap from:', apiUrl);
|
|
9530
|
+
|
|
9531
|
+
// Make a basic HTTP GET request to AuthScape API
|
|
9532
|
+
_context.next = 8;
|
|
9533
|
+
return fetch(apiUrl);
|
|
9534
|
+
case 8:
|
|
9521
9535
|
response = _context.sent;
|
|
9522
9536
|
if (response.ok) {
|
|
9523
|
-
_context.next =
|
|
9537
|
+
_context.next = 11;
|
|
9524
9538
|
break;
|
|
9525
9539
|
}
|
|
9526
9540
|
throw new Error("API request failed with status ".concat(response.status));
|
|
9527
|
-
case 9:
|
|
9528
|
-
_context.next = 11;
|
|
9529
|
-
return response.text();
|
|
9530
9541
|
case 11:
|
|
9542
|
+
_context.next = 13;
|
|
9543
|
+
return response.text();
|
|
9544
|
+
case 13:
|
|
9531
9545
|
sitemap = _context.sent;
|
|
9532
|
-
|
|
9546
|
+
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
9547
|
+
|
|
9548
|
+
// Set status code and headers BEFORE writing
|
|
9549
|
+
res.statusCode = 200;
|
|
9533
9550
|
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
|
|
9534
9551
|
res.setHeader('Cache-Control', 'public, s-maxage=86400, stale-while-revalidate');
|
|
9535
9552
|
|
|
9536
|
-
//
|
|
9553
|
+
// Write and end the response
|
|
9537
9554
|
res.write(sitemap);
|
|
9538
9555
|
res.end();
|
|
9539
9556
|
return _context.abrupt("return", {
|
|
9540
9557
|
props: {}
|
|
9541
9558
|
});
|
|
9542
|
-
case
|
|
9543
|
-
_context.prev =
|
|
9559
|
+
case 23:
|
|
9560
|
+
_context.prev = 23;
|
|
9544
9561
|
_context.t0 = _context["catch"](0);
|
|
9545
9562
|
console.error('AuthScape Sitemap Error:', _context.t0);
|
|
9546
9563
|
|
|
9547
|
-
//
|
|
9564
|
+
// Set status code BEFORE headers and writing
|
|
9548
9565
|
res.statusCode = 500;
|
|
9549
9566
|
res.setHeader('Content-Type', 'text/plain');
|
|
9550
9567
|
res.write("Error generating sitemap: ".concat(_context.t0.message || _context.t0));
|
|
@@ -9552,11 +9569,11 @@ function _generateSitemap() {
|
|
|
9552
9569
|
return _context.abrupt("return", {
|
|
9553
9570
|
props: {}
|
|
9554
9571
|
});
|
|
9555
|
-
case
|
|
9572
|
+
case 31:
|
|
9556
9573
|
case "end":
|
|
9557
9574
|
return _context.stop();
|
|
9558
9575
|
}
|
|
9559
|
-
}, _callee, null, [[0,
|
|
9576
|
+
}, _callee, null, [[0, 23]]);
|
|
9560
9577
|
}));
|
|
9561
9578
|
return _generateSitemap.apply(this, arguments);
|
|
9562
9579
|
}
|
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,7 +35,13 @@ 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
|
+
|
|
44
|
+
const response = await fetch(apiUrl);
|
|
35
45
|
|
|
36
46
|
if (!response.ok) {
|
|
37
47
|
throw new Error(`API request failed with status ${response.status}`);
|
|
@@ -40,6 +50,8 @@ export function createSitemapRoute(apiUri) {
|
|
|
40
50
|
// Get the sitemap XML
|
|
41
51
|
const sitemap = await response.text();
|
|
42
52
|
|
|
53
|
+
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
54
|
+
|
|
43
55
|
// Return the XML response with appropriate headers
|
|
44
56
|
return new Response(sitemap, {
|
|
45
57
|
status: 200,
|
|
@@ -51,7 +63,7 @@ export function createSitemapRoute(apiUri) {
|
|
|
51
63
|
} catch (error) {
|
|
52
64
|
console.error('AuthScape Sitemap Error:', error);
|
|
53
65
|
|
|
54
|
-
return new Response(
|
|
66
|
+
return new Response(`Error generating sitemap: ${error.message || error}`, {
|
|
55
67
|
status: 500,
|
|
56
68
|
headers: {
|
|
57
69
|
'Content-Type': 'text/plain',
|
|
@@ -25,9 +25,12 @@ 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);
|
|
28
31
|
|
|
29
32
|
// Make a basic HTTP GET request to AuthScape API
|
|
30
|
-
const response = await fetch(
|
|
33
|
+
const response = await fetch(apiUrl);
|
|
31
34
|
|
|
32
35
|
if (!response.ok) {
|
|
33
36
|
throw new Error(`API request failed with status ${response.status}`);
|
|
@@ -36,11 +39,14 @@ export async function generateSitemap(req, res, apiUri) {
|
|
|
36
39
|
// Get the sitemap XML from the API
|
|
37
40
|
const sitemap = await response.text();
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
console.log('Sitemap fetched successfully, length:', sitemap.length);
|
|
43
|
+
|
|
44
|
+
// Set status code and headers BEFORE writing
|
|
45
|
+
res.statusCode = 200;
|
|
40
46
|
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
|
|
41
47
|
res.setHeader('Cache-Control', 'public, s-maxage=86400, stale-while-revalidate');
|
|
42
48
|
|
|
43
|
-
//
|
|
49
|
+
// Write and end the response
|
|
44
50
|
res.write(sitemap);
|
|
45
51
|
res.end();
|
|
46
52
|
|
|
@@ -50,7 +56,7 @@ export async function generateSitemap(req, res, apiUri) {
|
|
|
50
56
|
} catch (error) {
|
|
51
57
|
console.error('AuthScape Sitemap Error:', error);
|
|
52
58
|
|
|
53
|
-
//
|
|
59
|
+
// Set status code BEFORE headers and writing
|
|
54
60
|
res.statusCode = 500;
|
|
55
61
|
res.setHeader('Content-Type', 'text/plain');
|
|
56
62
|
res.write(`Error generating sitemap: ${error.message || error}`);
|