reroute-js 0.43.4 → 0.43.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.
- package/cli/bin.d.ts +1 -1
- package/cli/bin.js +74 -6
- package/cli/bin.js.map +3 -3
- package/cli/index.d.ts +1 -1
- package/cli/index.js +4 -4
- package/cli/index.js.map +1 -1
- package/cli/src/cli.d.ts +1 -1
- package/cli/src/commands/analyze.d.ts +1 -1
- package/cli/src/commands/build.d.ts +1 -1
- package/cli/src/commands/dev.d.ts +1 -1
- package/cli/src/commands/gen.d.ts +1 -1
- package/cli/src/commands/index.d.ts +1 -1
- package/cli/src/commands/init.d.ts +1 -1
- package/cli/src/commands/lib/assets.d.ts +1 -1
- package/cli/src/commands/lib/bundler.d.ts +1 -1
- package/cli/src/commands/lib/command.d.ts +1 -1
- package/cli/src/commands/lib/env.d.ts +1 -1
- package/cli/src/commands/lib/index.d.ts +1 -1
- package/cli/src/commands/lib/log.d.ts +1 -1
- package/cli/src/commands/lib/markdown/availability.d.ts +1 -1
- package/cli/src/commands/lib/markdown/index.d.ts +1 -1
- package/cli/src/commands/lib/markdown/processor.d.ts +1 -1
- package/cli/src/commands/lib/production.d.ts +1 -1
- package/cli/src/commands/lib/server.d.ts +1 -1
- package/cli/src/commands/lib/streaming/analyzer.d.ts +1 -1
- package/cli/src/commands/lib/streaming/suspense.d.ts +1 -1
- package/cli/src/commands/lib/tailwind.d.ts +1 -1
- package/cli/src/commands/lib/terminal-ui.d.ts +1 -1
- package/cli/src/commands/lib/version.d.ts +1 -1
- package/cli/src/commands/og.d.ts +1 -1
- package/cli/src/commands/start.d.ts +1 -1
- package/cli/src/index.d.ts +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +70 -2
- package/core/index.js.map +3 -3
- package/core/src/bundler/hash.d.ts +1 -1
- package/core/src/bundler/index.d.ts +1 -1
- package/core/src/config.d.ts +1 -1
- package/core/src/content/discovery.d.ts +1 -1
- package/core/src/content/index.d.ts +1 -1
- package/core/src/content/metadata.d.ts +1 -1
- package/core/src/index.d.ts +1 -1
- package/core/src/llms/extractor.d.ts +1 -1
- package/core/src/llms/formatter.d.ts +1 -1
- package/core/src/llms/full-generator.d.ts +1 -1
- package/core/src/llms/index-generator.d.ts +1 -1
- package/core/src/llms/index.d.ts +1 -1
- package/core/src/og/discovery.d.ts +1 -1
- package/core/src/og/index.d.ts +1 -1
- package/core/src/og/meta.d.ts +1 -1
- package/core/src/og/render.d.ts +1 -1
- package/core/src/og/types.d.ts +1 -1
- package/core/src/robots/discovery.d.ts +1 -1
- package/core/src/robots/generator.d.ts +1 -1
- package/core/src/robots/index.d.ts +1 -1
- package/core/src/robots/policies.d.ts +1 -1
- package/core/src/rss/discovery.d.ts +1 -1
- package/core/src/rss/generator.d.ts +1 -1
- package/core/src/rss/index.d.ts +1 -1
- package/core/src/sitemap/discovery.d.ts +1 -1
- package/core/src/sitemap/generator.d.ts +1 -1
- package/core/src/sitemap/index.d.ts +1 -1
- package/core/src/ssr/index.d.ts +1 -1
- package/core/src/ssr/lib/cache.d.ts +53 -1
- package/core/src/ssr/lib/cache.d.ts.map +1 -1
- package/core/src/ssr/lib/collections.d.ts +1 -1
- package/core/src/ssr/lib/compression.d.ts +1 -1
- package/core/src/ssr/lib/compute/content.d.ts +1 -1
- package/core/src/ssr/lib/compute/index.d.ts +1 -1
- package/core/src/ssr/lib/compute/layouts.d.ts +1 -1
- package/core/src/ssr/lib/compute/routes.d.ts +1 -1
- package/core/src/ssr/lib/data.d.ts +1 -1
- package/core/src/ssr/lib/html.d.ts +1 -1
- package/core/src/ssr/lib/imports.d.ts +1 -1
- package/core/src/ssr/lib/index.d.ts +1 -1
- package/core/src/ssr/lib/layouts.d.ts +1 -1
- package/core/src/ssr/lib/metadata.d.ts +1 -1
- package/core/src/ssr/lib/mime.d.ts +1 -1
- package/core/src/ssr/lib/modules.d.ts +1 -1
- package/core/src/ssr/lib/path.d.ts +1 -1
- package/core/src/ssr/lib/preload.d.ts +1 -1
- package/core/src/ssr/lib/scripts/collections.d.ts +1 -1
- package/core/src/ssr/lib/scripts/data.d.ts +1 -1
- package/core/src/ssr/lib/scripts/escape.d.ts +1 -1
- package/core/src/ssr/lib/scripts/feeds.d.ts +1 -1
- package/core/src/ssr/lib/scripts/index.d.ts +1 -1
- package/core/src/ssr/lib/seed.d.ts +1 -1
- package/core/src/ssr/lib/serialize.d.ts +1 -1
- package/core/src/ssr/lib/setup.d.ts +1 -1
- package/core/src/ssr/lib/styles.d.ts +1 -1
- package/core/src/ssr/lib/template.d.ts +1 -1
- package/core/src/ssr/lib/types.d.ts +1 -1
- package/core/src/ssr/render.d.ts +1 -1
- package/core/src/ssr/stream.d.ts +1 -1
- package/elysia/index.d.ts +1 -1
- package/elysia/index.js +155 -106
- package/elysia/index.js.map +16 -16
- package/elysia/src/index.d.ts +1 -1
- package/elysia/src/libs/assets.d.ts +1 -1
- package/elysia/src/libs/cache.d.ts +1 -1
- package/elysia/src/libs/caching.d.ts +1 -1
- package/elysia/src/libs/http.d.ts +1 -1
- package/elysia/src/libs/image.d.ts +1 -1
- package/elysia/src/libs/index.d.ts +1 -1
- package/elysia/src/libs/llms.d.ts +1 -1
- package/elysia/src/libs/response.d.ts +1 -1
- package/elysia/src/libs/serving.d.ts +3 -3
- package/elysia/src/plugin.d.ts +1 -1
- package/elysia/src/plugin.d.ts.map +1 -1
- package/elysia/src/routes/artifacts.d.ts +3 -3
- package/elysia/src/routes/content.d.ts +3 -3
- package/elysia/src/routes/image.d.ts +1 -1
- package/elysia/src/routes/index.d.ts +1 -1
- package/elysia/src/routes/internal.d.ts +3 -3
- package/elysia/src/routes/internal.d.ts.map +1 -1
- package/elysia/src/routes/llms.d.ts +3 -3
- package/elysia/src/routes/llms.d.ts.map +1 -1
- package/elysia/src/routes/og.d.ts +3 -4
- package/elysia/src/routes/og.d.ts.map +1 -1
- package/elysia/src/routes/redirects.d.ts +1 -1
- package/elysia/src/routes/robots.d.ts +3 -4
- package/elysia/src/routes/robots.d.ts.map +1 -1
- package/elysia/src/routes/rss.d.ts +3 -4
- package/elysia/src/routes/rss.d.ts.map +1 -1
- package/elysia/src/routes/search.d.ts +1 -1
- package/elysia/src/routes/sitemap.d.ts +3 -4
- package/elysia/src/routes/sitemap.d.ts.map +1 -1
- package/elysia/src/routes/ssr.d.ts +1 -1
- package/elysia/src/routes/static.d.ts +3 -3
- package/elysia/src/types.d.ts +1 -1
- package/package.json +1 -1
- package/react/index.d.ts +1 -1
- package/react/index.js +2 -2
- package/react/index.js.map +1 -1
- package/react/src/components/ClientOnly.d.ts +1 -1
- package/react/src/components/ContentRoute.d.ts +1 -1
- package/react/src/components/Image.d.ts +1 -1
- package/react/src/components/LazyRoute.d.ts +1 -1
- package/react/src/components/Link.d.ts +1 -1
- package/react/src/components/Markdown.d.ts +1 -1
- package/react/src/components/Outlet.d.ts +1 -1
- package/react/src/components/index.d.ts +1 -1
- package/react/src/hooks/index.d.ts +1 -1
- package/react/src/hooks/useContent.d.ts +1 -1
- package/react/src/hooks/useData.d.ts +1 -1
- package/react/src/hooks/useFeed.d.ts +1 -1
- package/react/src/hooks/useLayoutData.d.ts +1 -1
- package/react/src/hooks/useLlms.d.ts +1 -1
- package/react/src/hooks/useNavigate.d.ts +1 -1
- package/react/src/hooks/useParams.d.ts +1 -1
- package/react/src/hooks/useRouter.d.ts +1 -1
- package/react/src/hooks/useSearch.d.ts +1 -1
- package/react/src/hooks/useSearchParams.d.ts +1 -1
- package/react/src/hooks/useToc.d.ts +1 -1
- package/react/src/index.d.ts +1 -1
- package/react/src/lib/collection.d.ts +1 -1
- package/react/src/lib/content.d.ts +1 -1
- package/react/src/lib/head.d.ts +1 -1
- package/react/src/lib/index.d.ts +1 -1
- package/react/src/lib/lazy-route.d.ts +1 -1
- package/react/src/lib/route-loader.d.ts +1 -1
- package/react/src/providers/ContentProvider.d.ts +1 -1
- package/react/src/providers/RerouteProvider.d.ts +1 -1
- package/react/src/providers/RouterProvider.d.ts +1 -1
- package/react/src/providers/index.d.ts +1 -1
- package/react/src/types/any.d.ts +1 -1
- package/react/src/types/index.d.ts +1 -1
- package/react/src/types/router.d.ts +1 -1
- package/telemetry/react.d.ts +1 -1
- package/telemetry/react.js +2 -2
- package/telemetry/react.js.map +1 -1
- package/telemetry/server.d.ts +1 -1
- package/telemetry/server.js +69 -2
- package/telemetry/server.js.map +3 -3
- package/telemetry/src/react/api.d.ts +1 -1
- package/telemetry/src/react/context.d.ts +1 -1
- package/telemetry/src/react/index.d.ts +1 -1
- package/telemetry/src/react/telemetry.d.ts +1 -1
- package/telemetry/src/server/context.d.ts +1 -1
- package/telemetry/src/server/headers/extractor.d.ts +1 -1
- package/telemetry/src/server/headers/index.d.ts +1 -1
- package/telemetry/src/server/headers/presets.d.ts +1 -1
- package/telemetry/src/server/index.d.ts +1 -1
- package/telemetry/src/server/instrumentation.d.ts +1 -1
- package/telemetry/src/server/plugin.d.ts +1 -1
- package/telemetry/src/server/sourcemap.d.ts +1 -1
package/elysia/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* reroute-js v0.43.
|
|
2
|
+
* reroute-js v0.43.6
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 stewones <hi@stewan.io>
|
|
@@ -491,6 +491,73 @@ class LRUCache {
|
|
|
491
491
|
this.cache.clear();
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
|
+
|
|
495
|
+
class TTLCache {
|
|
496
|
+
cache = new Map;
|
|
497
|
+
maxSize;
|
|
498
|
+
defaultTtlMs;
|
|
499
|
+
cleanupInterval = null;
|
|
500
|
+
constructor(maxSize = 100, defaultTtlMs = 300000, cleanupIntervalMs = 60000) {
|
|
501
|
+
this.maxSize = maxSize;
|
|
502
|
+
this.defaultTtlMs = defaultTtlMs;
|
|
503
|
+
this.cleanupInterval = setInterval(() => {
|
|
504
|
+
this.cleanup();
|
|
505
|
+
}, cleanupIntervalMs);
|
|
506
|
+
if (this.cleanupInterval.unref) {
|
|
507
|
+
this.cleanupInterval.unref();
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
get(key) {
|
|
511
|
+
const entry = this.cache.get(key);
|
|
512
|
+
if (!entry)
|
|
513
|
+
return;
|
|
514
|
+
if (entry.exp <= Date.now()) {
|
|
515
|
+
this.cache.delete(key);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
return entry.value;
|
|
519
|
+
}
|
|
520
|
+
set(key, value, ttlMs) {
|
|
521
|
+
this.cache.delete(key);
|
|
522
|
+
if (this.cache.size >= this.maxSize) {
|
|
523
|
+
const firstKey = this.cache.keys().next().value;
|
|
524
|
+
if (firstKey !== undefined) {
|
|
525
|
+
this.cache.delete(firstKey);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
this.cache.set(key, {
|
|
529
|
+
value,
|
|
530
|
+
exp: Date.now() + (ttlMs ?? this.defaultTtlMs)
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
has(key) {
|
|
534
|
+
return this.get(key) !== undefined;
|
|
535
|
+
}
|
|
536
|
+
delete(key) {
|
|
537
|
+
return this.cache.delete(key);
|
|
538
|
+
}
|
|
539
|
+
clear() {
|
|
540
|
+
this.cache.clear();
|
|
541
|
+
}
|
|
542
|
+
get size() {
|
|
543
|
+
return this.cache.size;
|
|
544
|
+
}
|
|
545
|
+
cleanup() {
|
|
546
|
+
const now = Date.now();
|
|
547
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
548
|
+
if (entry.exp <= now) {
|
|
549
|
+
this.cache.delete(key);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
destroy() {
|
|
554
|
+
if (this.cleanupInterval) {
|
|
555
|
+
clearInterval(this.cleanupInterval);
|
|
556
|
+
this.cleanupInterval = null;
|
|
557
|
+
}
|
|
558
|
+
this.clear();
|
|
559
|
+
}
|
|
560
|
+
}
|
|
494
561
|
var getGlobalCache = () => {
|
|
495
562
|
const g = globalThis;
|
|
496
563
|
if (!g.__REROUTE_SSR_CACHE__) {
|
|
@@ -5338,6 +5405,7 @@ __export(exports_core, {
|
|
|
5338
5405
|
allowAICrawlers: () => allowAICrawlers,
|
|
5339
5406
|
acceptsGzip: () => acceptsGzip,
|
|
5340
5407
|
acceptsBrotli: () => acceptsBrotli,
|
|
5408
|
+
TTLCache: () => TTLCache,
|
|
5341
5409
|
SSRDataCache: () => SSRDataCache,
|
|
5342
5410
|
SEARCH_CRAWLERS: () => SEARCH_CRAWLERS,
|
|
5343
5411
|
LRUCache: () => LRUCache,
|
|
@@ -6084,15 +6152,13 @@ function registerInternalRoutes(app, opts) {
|
|
|
6084
6152
|
async function handleKeyRequest(pathname, dataKey, headers2) {
|
|
6085
6153
|
const { computeSSRData: computeSSRData2 } = await Promise.resolve().then(() => (init_core(), exports_core));
|
|
6086
6154
|
const cacheKey = `${pathname}:promises`;
|
|
6087
|
-
let promiseData =
|
|
6155
|
+
let promiseData = dataCache?.get(cacheKey);
|
|
6088
6156
|
const promiseDataCached = promiseData !== undefined;
|
|
6089
6157
|
if (!promiseData) {
|
|
6090
6158
|
const sp = extractSearchParams(pathname);
|
|
6091
6159
|
const { data } = await computeSSRData2(pathname, clientDir, cwd, isWatchMode, { streaming: true, maxAge }, sp);
|
|
6092
6160
|
promiseData = data;
|
|
6093
|
-
|
|
6094
|
-
dataCache?.set(cacheKey, promiseData);
|
|
6095
|
-
}
|
|
6161
|
+
dataCache?.set(cacheKey, promiseData);
|
|
6096
6162
|
}
|
|
6097
6163
|
if (promiseData && typeof promiseData === "object") {
|
|
6098
6164
|
const value = promiseData[dataKey];
|
|
@@ -6396,18 +6462,6 @@ function registerLiveReloadRoutes(app, state) {
|
|
|
6396
6462
|
init_core();
|
|
6397
6463
|
import { NotFoundError as NotFoundError5 } from "elysia";
|
|
6398
6464
|
|
|
6399
|
-
// packages/elysia/src/libs/caching.ts
|
|
6400
|
-
function toTTL(seconds) {
|
|
6401
|
-
return seconds * 1000;
|
|
6402
|
-
}
|
|
6403
|
-
function isValid(entry) {
|
|
6404
|
-
return entry !== undefined && entry.exp > Date.now();
|
|
6405
|
-
}
|
|
6406
|
-
function getIfValid(cache2, key) {
|
|
6407
|
-
const entry = cache2.get(key);
|
|
6408
|
-
return isValid(entry) ? entry : undefined;
|
|
6409
|
-
}
|
|
6410
|
-
|
|
6411
6465
|
// packages/elysia/src/libs/llms.ts
|
|
6412
6466
|
function capitalize(str) {
|
|
6413
6467
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -6541,9 +6595,9 @@ function registerLLMsRoutes(app, options) {
|
|
|
6541
6595
|
llmsConfig,
|
|
6542
6596
|
collections: collections2
|
|
6543
6597
|
} = options;
|
|
6544
|
-
const llmsCache = new Map;
|
|
6545
6598
|
const defaults = calculateLlmsDefaults(llmsConfig, maxAge);
|
|
6546
6599
|
const { ttlMs, ttlMsFull, baseUrl } = defaults;
|
|
6600
|
+
const llmsCache = new TTLCache(100, ttlMs);
|
|
6547
6601
|
const availableLlms = [];
|
|
6548
6602
|
const responseOpts = {
|
|
6549
6603
|
maxAge: defaults.maxAge,
|
|
@@ -6558,9 +6612,9 @@ function registerLLMsRoutes(app, options) {
|
|
|
6558
6612
|
app.get("/llms.txt", async () => {
|
|
6559
6613
|
const cacheKey = buildLlmsIndexCacheKey();
|
|
6560
6614
|
try {
|
|
6561
|
-
const cached =
|
|
6615
|
+
const cached = llmsCache.get(cacheKey);
|
|
6562
6616
|
if (cached) {
|
|
6563
|
-
return textResponse(cached
|
|
6617
|
+
return textResponse(cached, {
|
|
6564
6618
|
...responseOpts,
|
|
6565
6619
|
cacheStatus: "HIT"
|
|
6566
6620
|
});
|
|
@@ -6572,7 +6626,7 @@ function registerLLMsRoutes(app, options) {
|
|
|
6572
6626
|
isWatchMode,
|
|
6573
6627
|
llmsConfig
|
|
6574
6628
|
});
|
|
6575
|
-
llmsCache.set(cacheKey,
|
|
6629
|
+
llmsCache.set(cacheKey, content2);
|
|
6576
6630
|
return textResponse(content2, { ...responseOpts, cacheStatus: "MISS" });
|
|
6577
6631
|
} catch (error) {
|
|
6578
6632
|
console.error("[reroute/llms] Failed to generate index:", error);
|
|
@@ -6584,9 +6638,9 @@ function registerLLMsRoutes(app, options) {
|
|
|
6584
6638
|
app.get("/llms-full.txt", async () => {
|
|
6585
6639
|
const cacheKey = buildLlmsFullCacheKey();
|
|
6586
6640
|
try {
|
|
6587
|
-
const cached =
|
|
6641
|
+
const cached = llmsCache.get(cacheKey);
|
|
6588
6642
|
if (cached) {
|
|
6589
|
-
return textResponse(cached
|
|
6643
|
+
return textResponse(cached, {
|
|
6590
6644
|
...responseOptsFull,
|
|
6591
6645
|
cacheStatus: "HIT"
|
|
6592
6646
|
});
|
|
@@ -6604,7 +6658,7 @@ function registerLLMsRoutes(app, options) {
|
|
|
6604
6658
|
llmsConfig
|
|
6605
6659
|
});
|
|
6606
6660
|
console.log(`[reroute/llms] Generated llms-full.txt: ${stats.itemCount} items, ${formatByteSize(stats.byteSize)}MB`);
|
|
6607
|
-
llmsCache.set(cacheKey,
|
|
6661
|
+
llmsCache.set(cacheKey, content2, ttlMsFull);
|
|
6608
6662
|
return textResponse(content2, {
|
|
6609
6663
|
...responseOptsFull,
|
|
6610
6664
|
cacheStatus: "MISS"
|
|
@@ -6624,9 +6678,9 @@ function registerLLMsRoutes(app, options) {
|
|
|
6624
6678
|
app.get(`/${collection}/llms.txt`, async () => {
|
|
6625
6679
|
const cacheKey = buildLlmsIndexCacheKey(collection);
|
|
6626
6680
|
try {
|
|
6627
|
-
const cached =
|
|
6681
|
+
const cached = llmsCache.get(cacheKey);
|
|
6628
6682
|
if (cached) {
|
|
6629
|
-
return textResponse(cached
|
|
6683
|
+
return textResponse(cached, {
|
|
6630
6684
|
...responseOpts,
|
|
6631
6685
|
cacheStatus: "HIT"
|
|
6632
6686
|
});
|
|
@@ -6642,7 +6696,7 @@ function registerLLMsRoutes(app, options) {
|
|
|
6642
6696
|
siteDescription: meta.description
|
|
6643
6697
|
}
|
|
6644
6698
|
});
|
|
6645
|
-
llmsCache.set(cacheKey,
|
|
6699
|
+
llmsCache.set(cacheKey, content2);
|
|
6646
6700
|
return textResponse(content2, {
|
|
6647
6701
|
...responseOpts,
|
|
6648
6702
|
cacheStatus: "MISS"
|
|
@@ -6657,9 +6711,9 @@ function registerLLMsRoutes(app, options) {
|
|
|
6657
6711
|
app.get(`/${collection}/llms-full.txt`, async () => {
|
|
6658
6712
|
const cacheKey = buildLlmsFullCacheKey(collection);
|
|
6659
6713
|
try {
|
|
6660
|
-
const cached =
|
|
6714
|
+
const cached = llmsCache.get(cacheKey);
|
|
6661
6715
|
if (cached) {
|
|
6662
|
-
return textResponse(cached
|
|
6716
|
+
return textResponse(cached, {
|
|
6663
6717
|
...responseOptsFull,
|
|
6664
6718
|
cacheStatus: "HIT"
|
|
6665
6719
|
});
|
|
@@ -6681,7 +6735,7 @@ function registerLLMsRoutes(app, options) {
|
|
|
6681
6735
|
}
|
|
6682
6736
|
});
|
|
6683
6737
|
console.log(`[reroute/llms] Generated ${collection}/llms-full.txt: ${stats.itemCount} items, ${formatByteSize(stats.byteSize)}MB`);
|
|
6684
|
-
llmsCache.set(cacheKey,
|
|
6738
|
+
llmsCache.set(cacheKey, content2, ttlMsFull);
|
|
6685
6739
|
return textResponse(content2, {
|
|
6686
6740
|
...responseOptsFull,
|
|
6687
6741
|
cacheStatus: "MISS"
|
|
@@ -6696,12 +6750,12 @@ function registerLLMsRoutes(app, options) {
|
|
|
6696
6750
|
if (shouldEnableContentNegotiation(llmsConfig)) {
|
|
6697
6751
|
async function handleLLMRequest(pathname, format, acceptEncoding) {
|
|
6698
6752
|
const cacheKey = buildLlmsCacheKey(pathname, format, acceptEncoding);
|
|
6699
|
-
const cached =
|
|
6753
|
+
const cached = llmsCache.get(cacheKey);
|
|
6700
6754
|
if (cached) {
|
|
6701
|
-
return format === "md" ? markdownResponse(cached
|
|
6755
|
+
return format === "md" ? markdownResponse(cached, {
|
|
6702
6756
|
...responseOpts,
|
|
6703
6757
|
cacheStatus: "HIT"
|
|
6704
|
-
}) : textResponse(cached
|
|
6758
|
+
}) : textResponse(cached, {
|
|
6705
6759
|
...responseOpts,
|
|
6706
6760
|
extraHeaders: { Vary: "Accept" },
|
|
6707
6761
|
cacheStatus: "HIT"
|
|
@@ -6718,7 +6772,7 @@ function registerLLMsRoutes(app, options) {
|
|
|
6718
6772
|
format,
|
|
6719
6773
|
llmsConfig
|
|
6720
6774
|
});
|
|
6721
|
-
llmsCache.set(cacheKey,
|
|
6775
|
+
llmsCache.set(cacheKey, content2);
|
|
6722
6776
|
return format === "md" ? markdownResponse(content2, { ...responseOpts, cacheStatus: "MISS" }) : textResponse(content2, {
|
|
6723
6777
|
...responseOpts,
|
|
6724
6778
|
extraHeaders: { Vary: "Accept" },
|
|
@@ -6962,14 +7016,12 @@ function registerOGRoutes(app, options) {
|
|
|
6962
7016
|
return pathname;
|
|
6963
7017
|
}
|
|
6964
7018
|
function checkOgCache(pathname, set) {
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
return new Response(cached.buffer);
|
|
6972
|
-
}
|
|
7019
|
+
const cached = ogCache.get(pathname);
|
|
7020
|
+
if (cached) {
|
|
7021
|
+
set.headers["content-type"] = "image/png";
|
|
7022
|
+
set.headers["cache-control"] = `public, max-age=${maxAge}`;
|
|
7023
|
+
set.headers["Reroute-Cache"] = "HIT";
|
|
7024
|
+
return new Response(cached);
|
|
6973
7025
|
}
|
|
6974
7026
|
return;
|
|
6975
7027
|
}
|
|
@@ -7040,9 +7092,7 @@ function registerOGRoutes(app, options) {
|
|
|
7040
7092
|
siteName: routeOgImage?.siteName ?? ogConfig2.siteName,
|
|
7041
7093
|
baseUrl: ogConfig2.baseUrl
|
|
7042
7094
|
}, { width: width2, height: height2, fonts });
|
|
7043
|
-
|
|
7044
|
-
ogCache.set(pathname, { buffer, exp: Date.now() + maxAge * 1000 });
|
|
7045
|
-
}
|
|
7095
|
+
ogCache.set(pathname, buffer);
|
|
7046
7096
|
}
|
|
7047
7097
|
app.get("/__reroute_og/*", async ({ request, set }) => {
|
|
7048
7098
|
try {
|
|
@@ -7204,16 +7254,15 @@ function registerRobotsRoute(app, options) {
|
|
|
7204
7254
|
sitemapEnabled,
|
|
7205
7255
|
redirects
|
|
7206
7256
|
} = options;
|
|
7207
|
-
const ttlMs = toTTL(maxAge);
|
|
7208
7257
|
app.get("/robots.txt", async () => {
|
|
7209
7258
|
try {
|
|
7210
|
-
const cached =
|
|
7259
|
+
const cached = robotsCache.get("robots:main");
|
|
7211
7260
|
if (cached) {
|
|
7212
|
-
return textResponse(cached
|
|
7261
|
+
return textResponse(cached, { maxAge, cacheStatus: "HIT" });
|
|
7213
7262
|
}
|
|
7214
7263
|
const discovery5 = await discoverRobotsData(cwd, isWatchMode, robotsConfig, sitemapConfig, redirects);
|
|
7215
7264
|
const txt = generateRobots(discovery5, robotsConfig, sitemapEnabled);
|
|
7216
|
-
robotsCache.set("robots:main",
|
|
7265
|
+
robotsCache.set("robots:main", txt);
|
|
7217
7266
|
return textResponse(txt, { maxAge, cacheStatus: "MISS" });
|
|
7218
7267
|
} catch (error) {
|
|
7219
7268
|
console.error("[reroute] Failed to generate robots.txt:", error);
|
|
@@ -7226,21 +7275,24 @@ function registerRobotsRoute(app, options) {
|
|
|
7226
7275
|
// packages/elysia/src/routes/rss.ts
|
|
7227
7276
|
init_core();
|
|
7228
7277
|
import { NotFoundError as NotFoundError8 } from "elysia";
|
|
7229
|
-
|
|
7278
|
+
|
|
7279
|
+
// packages/elysia/src/libs/caching.ts
|
|
7280
|
+
function toTTL(seconds) {
|
|
7281
|
+
return seconds * 1000;
|
|
7282
|
+
}
|
|
7283
|
+
|
|
7284
|
+
// packages/elysia/src/routes/rss.ts
|
|
7285
|
+
var rssDiscoveryCache = new TTLCache(1, 5 * 60 * 1000);
|
|
7230
7286
|
async function getOrDiscoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig) {
|
|
7231
7287
|
if (isWatchMode) {
|
|
7232
7288
|
return discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
|
|
7233
7289
|
}
|
|
7234
7290
|
const cacheKey = "rss:discovery";
|
|
7235
7291
|
const cached = rssDiscoveryCache.get(cacheKey);
|
|
7236
|
-
if (cached
|
|
7237
|
-
return cached
|
|
7238
|
-
}
|
|
7292
|
+
if (cached)
|
|
7293
|
+
return cached;
|
|
7239
7294
|
const discovery5 = await discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
|
|
7240
|
-
rssDiscoveryCache.set(cacheKey,
|
|
7241
|
-
discovery: discovery5,
|
|
7242
|
-
exp: Date.now() + 5 * 60 * 1000
|
|
7243
|
-
});
|
|
7295
|
+
rssDiscoveryCache.set(cacheKey, discovery5);
|
|
7244
7296
|
return discovery5;
|
|
7245
7297
|
}
|
|
7246
7298
|
function createFeedTitle(configTitle, name) {
|
|
@@ -7266,12 +7318,12 @@ async function discoverSSRRoutes(cwd, isWatchMode) {
|
|
|
7266
7318
|
return [];
|
|
7267
7319
|
}
|
|
7268
7320
|
}
|
|
7269
|
-
async function registerMainFeedRoute(app, cwd, collections2, baseUrl, isWatchMode, rssCache, format, limit, maxAge,
|
|
7321
|
+
async function registerMainFeedRoute(app, cwd, collections2, baseUrl, isWatchMode, rssCache, format, limit, maxAge, _ttlMs, feedTitle, feedDescription, rssConfig) {
|
|
7270
7322
|
app.get("/feed.xml", async () => {
|
|
7271
7323
|
try {
|
|
7272
|
-
const cached =
|
|
7324
|
+
const cached = rssCache.get("rss:main");
|
|
7273
7325
|
if (cached) {
|
|
7274
|
-
return feedResponse(cached
|
|
7326
|
+
return feedResponse(cached, format, { maxAge, cacheStatus: "HIT" });
|
|
7275
7327
|
}
|
|
7276
7328
|
const discovery5 = await getOrDiscoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
|
|
7277
7329
|
const allItems = [
|
|
@@ -7291,7 +7343,7 @@ async function registerMainFeedRoute(app, cwd, collections2, baseUrl, isWatchMod
|
|
|
7291
7343
|
items: allItems
|
|
7292
7344
|
};
|
|
7293
7345
|
const xml = generateFeed(feed, { format, limit });
|
|
7294
|
-
rssCache.set("rss:main",
|
|
7346
|
+
rssCache.set("rss:main", xml);
|
|
7295
7347
|
return feedResponse(xml, format, { maxAge, cacheStatus: "MISS" });
|
|
7296
7348
|
} catch (error) {
|
|
7297
7349
|
console.error("[reroute] Failed to generate main feed:", error);
|
|
@@ -7305,9 +7357,9 @@ function registerCollectionFeedRoutes(app, collections2, options) {
|
|
|
7305
7357
|
app.get(`/${collection}/feed.xml`, async () => {
|
|
7306
7358
|
const cacheKey = `rss:${collection}`;
|
|
7307
7359
|
try {
|
|
7308
|
-
const cached =
|
|
7360
|
+
const cached = options.rssCache.get(cacheKey);
|
|
7309
7361
|
if (cached) {
|
|
7310
|
-
return feedResponse(cached
|
|
7362
|
+
return feedResponse(cached, options.format, {
|
|
7311
7363
|
maxAge: options.maxAge,
|
|
7312
7364
|
cacheStatus: "HIT"
|
|
7313
7365
|
});
|
|
@@ -7326,10 +7378,7 @@ function registerCollectionFeedRoutes(app, collections2, options) {
|
|
|
7326
7378
|
format: options.format,
|
|
7327
7379
|
limit: options.limit
|
|
7328
7380
|
});
|
|
7329
|
-
options.rssCache.set(cacheKey,
|
|
7330
|
-
xml,
|
|
7331
|
-
exp: Date.now() + options.ttlMs
|
|
7332
|
-
});
|
|
7381
|
+
options.rssCache.set(cacheKey, xml);
|
|
7333
7382
|
return feedResponse(xml, options.format, {
|
|
7334
7383
|
maxAge: options.maxAge,
|
|
7335
7384
|
cacheStatus: "MISS"
|
|
@@ -7364,9 +7413,9 @@ async function discoverRoutesWithFeeds(ssrDataRoutes, collections2, options) {
|
|
|
7364
7413
|
async function generateSSRDataFeed(route, options) {
|
|
7365
7414
|
const routeName = route.pattern.replace(/^\//, "") || "index";
|
|
7366
7415
|
const cacheKey = `rss:${routeName}`;
|
|
7367
|
-
const cached =
|
|
7416
|
+
const cached = options.rssCache.get(cacheKey);
|
|
7368
7417
|
if (cached) {
|
|
7369
|
-
return feedResponse(cached
|
|
7418
|
+
return feedResponse(cached, options.format, {
|
|
7370
7419
|
maxAge: options.maxAge,
|
|
7371
7420
|
cacheStatus: "HIT"
|
|
7372
7421
|
});
|
|
@@ -7388,10 +7437,7 @@ async function generateSSRDataFeed(route, options) {
|
|
|
7388
7437
|
format: options.format,
|
|
7389
7438
|
limit: options.limit
|
|
7390
7439
|
});
|
|
7391
|
-
options.rssCache.set(cacheKey,
|
|
7392
|
-
xml,
|
|
7393
|
-
exp: Date.now() + options.ttlMs
|
|
7394
|
-
});
|
|
7440
|
+
options.rssCache.set(cacheKey, xml);
|
|
7395
7441
|
return feedResponse(xml, options.format, {
|
|
7396
7442
|
maxAge: options.maxAge,
|
|
7397
7443
|
cacheStatus: "MISS"
|
|
@@ -7598,21 +7644,17 @@ function registerSearchRoute(app, cwd, directive, maxAge, searchConfig) {
|
|
|
7598
7644
|
// packages/elysia/src/routes/sitemap.ts
|
|
7599
7645
|
init_core();
|
|
7600
7646
|
import { NotFoundError as NotFoundError9 } from "elysia";
|
|
7601
|
-
var sitemapDiscoveryCache = new
|
|
7647
|
+
var sitemapDiscoveryCache = new TTLCache(1, 5 * 60 * 1000);
|
|
7602
7648
|
async function getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig) {
|
|
7603
7649
|
if (isWatchMode) {
|
|
7604
7650
|
return discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
|
|
7605
7651
|
}
|
|
7606
7652
|
const cacheKey = "sitemap:discovery";
|
|
7607
7653
|
const cached = sitemapDiscoveryCache.get(cacheKey);
|
|
7608
|
-
if (cached
|
|
7609
|
-
return cached
|
|
7610
|
-
}
|
|
7654
|
+
if (cached)
|
|
7655
|
+
return cached;
|
|
7611
7656
|
const discovery5 = await discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
|
|
7612
|
-
sitemapDiscoveryCache.set(cacheKey,
|
|
7613
|
-
discovery: discovery5,
|
|
7614
|
-
exp: Date.now() + 5 * 60 * 1000
|
|
7615
|
-
});
|
|
7657
|
+
sitemapDiscoveryCache.set(cacheKey, discovery5);
|
|
7616
7658
|
return discovery5;
|
|
7617
7659
|
}
|
|
7618
7660
|
async function generateAndCacheSitemap(options, _ttlMs) {
|
|
@@ -7635,23 +7677,17 @@ function registerSitemapRoutes(app, options) {
|
|
|
7635
7677
|
const ttlMs = toTTL(maxAge);
|
|
7636
7678
|
app.get("/sitemap.xml", async () => {
|
|
7637
7679
|
try {
|
|
7638
|
-
const cached =
|
|
7680
|
+
const cached = sitemapCache.get("sitemap:main");
|
|
7639
7681
|
if (cached) {
|
|
7640
|
-
return xmlResponse(cached
|
|
7682
|
+
return xmlResponse(cached, { maxAge, cacheStatus: "HIT" });
|
|
7641
7683
|
}
|
|
7642
7684
|
const result = await generateAndCacheSitemap(options, ttlMs);
|
|
7643
7685
|
if (result.needsIndex) {
|
|
7644
7686
|
for (const page of result.pages) {
|
|
7645
|
-
sitemapCache.set(`sitemap:${page.filename}`,
|
|
7646
|
-
xml: page.xml,
|
|
7647
|
-
exp: Date.now() + ttlMs
|
|
7648
|
-
});
|
|
7687
|
+
sitemapCache.set(`sitemap:${page.filename}`, page.xml);
|
|
7649
7688
|
}
|
|
7650
7689
|
}
|
|
7651
|
-
sitemapCache.set("sitemap:main",
|
|
7652
|
-
xml: result.xml,
|
|
7653
|
-
exp: Date.now() + ttlMs
|
|
7654
|
-
});
|
|
7690
|
+
sitemapCache.set("sitemap:main", result.xml);
|
|
7655
7691
|
return xmlResponse(result.xml, { maxAge, cacheStatus: "MISS" });
|
|
7656
7692
|
} catch (error) {
|
|
7657
7693
|
console.error("[reroute] Failed to generate sitemap:", error);
|
|
@@ -7667,19 +7703,16 @@ function registerSitemapRoutes(app, options) {
|
|
|
7667
7703
|
const filename = `sitemap-${pageMatch[1]}.xml`;
|
|
7668
7704
|
const cacheKey = `sitemap:${filename}`;
|
|
7669
7705
|
try {
|
|
7670
|
-
const cached =
|
|
7706
|
+
const cached = sitemapCache.get(cacheKey);
|
|
7671
7707
|
if (cached) {
|
|
7672
|
-
return xmlResponse(cached
|
|
7708
|
+
return xmlResponse(cached, { maxAge, cacheStatus: "HIT" });
|
|
7673
7709
|
}
|
|
7674
7710
|
const result = await generateAndCacheSitemap(options, ttlMs);
|
|
7675
7711
|
const pageData = result.pages.find((p) => p.filename === filename);
|
|
7676
7712
|
if (!pageData) {
|
|
7677
7713
|
throw new NotFoundError9;
|
|
7678
7714
|
}
|
|
7679
|
-
sitemapCache.set(cacheKey,
|
|
7680
|
-
xml: pageData.xml,
|
|
7681
|
-
exp: Date.now() + ttlMs
|
|
7682
|
-
});
|
|
7715
|
+
sitemapCache.set(cacheKey, pageData.xml);
|
|
7683
7716
|
return xmlResponse(pageData.xml, { maxAge, cacheStatus: "MISS" });
|
|
7684
7717
|
} catch (error) {
|
|
7685
7718
|
if (error instanceof NotFoundError9)
|
|
@@ -8321,13 +8354,14 @@ var reroute = () => async (app) => {
|
|
|
8321
8354
|
const llmsEnabled = llmsConfig?.enabled === true;
|
|
8322
8355
|
const robotsConfig = globalConfig.robots;
|
|
8323
8356
|
const robotsEnabled = robotsConfig?.enabled === true;
|
|
8324
|
-
const
|
|
8325
|
-
const
|
|
8326
|
-
const
|
|
8327
|
-
const
|
|
8328
|
-
const
|
|
8329
|
-
const
|
|
8330
|
-
const
|
|
8357
|
+
const serverTtlMs = serverMaxAge * 1000;
|
|
8358
|
+
const fileCache = new TTLCache(100, serverTtlMs);
|
|
8359
|
+
const dataCache = new TTLCache(100, serverTtlMs);
|
|
8360
|
+
const collectionCache = new TTLCache(50, serverTtlMs);
|
|
8361
|
+
const sitemapCache = new TTLCache(20, serverTtlMs);
|
|
8362
|
+
const rssCache = new TTLCache(20, serverTtlMs);
|
|
8363
|
+
const ogCache = new TTLCache(100, serverTtlMs);
|
|
8364
|
+
const robotsCache = new TTLCache(10, serverTtlMs);
|
|
8331
8365
|
const liveReloadState = {
|
|
8332
8366
|
clients: new Set,
|
|
8333
8367
|
pendingReload: false
|
|
@@ -8411,7 +8445,22 @@ var reroute = () => async (app) => {
|
|
|
8411
8445
|
const startupCollections = await loadCollections2(cwd, isWatchMode);
|
|
8412
8446
|
const startupTailwindCSS = await inlineTailwindCSS2(clientDir, false, isWatchMode);
|
|
8413
8447
|
const startupIndexHtml = await loadIndexHtml2(clientDir);
|
|
8414
|
-
const
|
|
8448
|
+
const collectionsTtlMs = serverMaxAge * 1000;
|
|
8449
|
+
let collectionsCache = serverCacheEnabled ? { data: startupCollections, exp: Date.now() + collectionsTtlMs } : null;
|
|
8450
|
+
const getCollections = isWatchMode ? () => loadCollections2(cwd, isWatchMode) : async () => {
|
|
8451
|
+
if (!serverCacheEnabled) {
|
|
8452
|
+
return loadCollections2(cwd, isWatchMode);
|
|
8453
|
+
}
|
|
8454
|
+
if (collectionsCache && collectionsCache.exp > Date.now()) {
|
|
8455
|
+
return collectionsCache.data;
|
|
8456
|
+
}
|
|
8457
|
+
const fresh = await loadCollections2(cwd, isWatchMode);
|
|
8458
|
+
collectionsCache = {
|
|
8459
|
+
data: fresh,
|
|
8460
|
+
exp: Date.now() + collectionsTtlMs
|
|
8461
|
+
};
|
|
8462
|
+
return fresh;
|
|
8463
|
+
};
|
|
8415
8464
|
const getTailwindCSS = isWatchMode ? () => inlineTailwindCSS2(clientDir, false, isWatchMode) : async () => startupTailwindCSS;
|
|
8416
8465
|
const getIndexHtml = isWatchMode ? () => loadIndexHtml2(clientDir) : async () => startupIndexHtml;
|
|
8417
8466
|
if (globalConfig.redirects && globalConfig.redirects.length > 0) {
|
|
@@ -8601,4 +8650,4 @@ export {
|
|
|
8601
8650
|
reroute
|
|
8602
8651
|
};
|
|
8603
8652
|
|
|
8604
|
-
//# debugId=
|
|
8653
|
+
//# debugId=F52BE988669929F264756E2164756E21
|