reroute-js 0.41.0 → 0.42.0
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 +115 -48
- package/cli/bin.js.map +6 -6
- 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/gen.d.ts.map +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 +57 -23
- package/core/index.js.map +5 -5
- package/core/src/bundler/hash.d.ts +1 -1
- package/core/src/bundler/index.d.ts +1 -1
- package/core/src/config.d.ts +6 -4
- package/core/src/config.d.ts.map +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/discovery.d.ts.map +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/discovery.d.ts.map +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 +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 +232 -104
- package/elysia/index.js.map +10 -10
- 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 +1 -1
- package/elysia/src/plugin.d.ts +1 -1
- package/elysia/src/plugin.d.ts.map +1 -1
- package/elysia/src/routes/artifacts.d.ts +1 -1
- package/elysia/src/routes/content.d.ts +1 -1
- 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 +1 -1
- package/elysia/src/routes/internal.d.ts.map +1 -1
- package/elysia/src/routes/llms.d.ts +1 -1
- package/elysia/src/routes/og.d.ts +1 -1
- 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 +1 -1
- package/elysia/src/routes/rss.d.ts +2 -2
- 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 +2 -2
- 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 +1 -1
- 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 +2 -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.
|
|
2
|
+
* reroute-js v0.42.0
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 stewones <hi@stewan.io>
|
|
@@ -4061,13 +4061,13 @@ async function discoverSSRDataRoutes2(cwd, staticRoutes, isWatchMode, baseUrl, s
|
|
|
4061
4061
|
const ssrDataRoutes = new Map;
|
|
4062
4062
|
const bundledRoutes = globalThis.__REROUTE_ROUTES__;
|
|
4063
4063
|
if (bundledRoutes && Array.isArray(bundledRoutes)) {
|
|
4064
|
-
|
|
4064
|
+
const routePromises = staticRoutes.map(async (route) => {
|
|
4065
4065
|
if (sitemapConfig?.excludeDiscovery?.some((excluded) => route.pattern.startsWith(excluded))) {
|
|
4066
|
-
|
|
4066
|
+
return null;
|
|
4067
4067
|
}
|
|
4068
4068
|
const bundledRoute = bundledRoutes.find((r) => r?.pattern === route.pattern);
|
|
4069
4069
|
if (!bundledRoute)
|
|
4070
|
-
|
|
4070
|
+
return null;
|
|
4071
4071
|
const ssr = bundledRoute?.ssr;
|
|
4072
4072
|
const dataFn = ssr?.data;
|
|
4073
4073
|
if (typeof dataFn === "function") {
|
|
@@ -4080,15 +4080,22 @@ async function discoverSSRDataRoutes2(cwd, staticRoutes, isWatchMode, baseUrl, s
|
|
|
4080
4080
|
});
|
|
4081
4081
|
const entries = extractEntriesFromData(result, route.pattern, baseUrl, sitemapConfig);
|
|
4082
4082
|
if (entries.length > 0) {
|
|
4083
|
-
|
|
4083
|
+
return { pattern: route.pattern, entries };
|
|
4084
4084
|
}
|
|
4085
4085
|
} catch {}
|
|
4086
4086
|
}
|
|
4087
|
+
return null;
|
|
4088
|
+
});
|
|
4089
|
+
const results = await Promise.all(routePromises);
|
|
4090
|
+
for (const result of results) {
|
|
4091
|
+
if (result) {
|
|
4092
|
+
ssrDataRoutes.set(result.pattern, result.entries);
|
|
4093
|
+
}
|
|
4087
4094
|
}
|
|
4088
4095
|
} else {
|
|
4089
|
-
|
|
4096
|
+
const routePromises = staticRoutes.map(async (route) => {
|
|
4090
4097
|
if (sitemapConfig?.excludeDiscovery?.some((excluded) => route.pattern.startsWith(excluded))) {
|
|
4091
|
-
|
|
4098
|
+
return null;
|
|
4092
4099
|
}
|
|
4093
4100
|
try {
|
|
4094
4101
|
const routeModulePath = join(cwd, "src", "client", "routes", route.path);
|
|
@@ -4104,10 +4111,17 @@ async function discoverSSRDataRoutes2(cwd, staticRoutes, isWatchMode, baseUrl, s
|
|
|
4104
4111
|
});
|
|
4105
4112
|
const entries = extractEntriesFromData(result, route.pattern, baseUrl, sitemapConfig);
|
|
4106
4113
|
if (entries.length > 0) {
|
|
4107
|
-
|
|
4114
|
+
return { pattern: route.pattern, entries };
|
|
4108
4115
|
}
|
|
4109
4116
|
}
|
|
4110
4117
|
} catch {}
|
|
4118
|
+
return null;
|
|
4119
|
+
});
|
|
4120
|
+
const results = await Promise.all(routePromises);
|
|
4121
|
+
for (const result of results) {
|
|
4122
|
+
if (result) {
|
|
4123
|
+
ssrDataRoutes.set(result.pattern, result.entries);
|
|
4124
|
+
}
|
|
4111
4125
|
}
|
|
4112
4126
|
}
|
|
4113
4127
|
return ssrDataRoutes;
|
|
@@ -4170,6 +4184,8 @@ function extractIdentifierFromItem(item, routePattern, sitemapConfig) {
|
|
|
4170
4184
|
if (sitemapConfig?.extractUrl) {
|
|
4171
4185
|
try {
|
|
4172
4186
|
const identifier2 = sitemapConfig.extractUrl(item, routePattern);
|
|
4187
|
+
if (identifier2 === false)
|
|
4188
|
+
return null;
|
|
4173
4189
|
if (identifier2)
|
|
4174
4190
|
return identifier2;
|
|
4175
4191
|
} catch (error) {
|
|
@@ -4425,6 +4441,8 @@ function extractIdentifier2(item, routePattern, rssConfig) {
|
|
|
4425
4441
|
if (rssConfig?.extractUrl) {
|
|
4426
4442
|
try {
|
|
4427
4443
|
const identifier = rssConfig.extractUrl(item, routePattern);
|
|
4444
|
+
if (identifier === false)
|
|
4445
|
+
return null;
|
|
4428
4446
|
if (identifier)
|
|
4429
4447
|
return String(identifier);
|
|
4430
4448
|
} catch (error) {
|
|
@@ -4483,24 +4501,28 @@ function createRSSItemFromData(item, routePattern, baseUrl, rssConfig) {
|
|
|
4483
4501
|
}
|
|
4484
4502
|
async function discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig) {
|
|
4485
4503
|
const collectionsMap = new Map;
|
|
4486
|
-
|
|
4504
|
+
const collectionPromises = collections2.map(async (collection) => {
|
|
4487
4505
|
const items = await discoverCollectionFeedItems(cwd, collection, isWatchMode, baseUrl, rssConfig);
|
|
4488
|
-
|
|
4489
|
-
|
|
4506
|
+
return items.length > 0 ? { collection, items } : null;
|
|
4507
|
+
});
|
|
4508
|
+
const collectionResults = await Promise.all(collectionPromises);
|
|
4509
|
+
for (const result of collectionResults) {
|
|
4510
|
+
if (result) {
|
|
4511
|
+
collectionsMap.set(result.collection, result.items);
|
|
4490
4512
|
}
|
|
4491
4513
|
}
|
|
4492
4514
|
const ssrDataFeeds = new Map;
|
|
4493
4515
|
const bundledRoutes = globalThis.__REROUTE_ROUTES__;
|
|
4516
|
+
const { discoverRoutes: discoverRoutes2 } = await Promise.resolve().then(() => (init_discovery4(), exports_discovery));
|
|
4517
|
+
const { staticRoutes } = await discoverRoutes2(cwd, isWatchMode);
|
|
4494
4518
|
if (bundledRoutes && Array.isArray(bundledRoutes)) {
|
|
4495
|
-
const
|
|
4496
|
-
const { staticRoutes } = await discoverRoutes2(cwd, isWatchMode);
|
|
4497
|
-
for (const route of staticRoutes) {
|
|
4519
|
+
const routePromises = staticRoutes.map(async (route) => {
|
|
4498
4520
|
if (rssConfig?.excludeDiscovery?.some((excluded) => route.pattern.startsWith(excluded))) {
|
|
4499
|
-
|
|
4521
|
+
return null;
|
|
4500
4522
|
}
|
|
4501
4523
|
const bundledRoute = bundledRoutes.find((r) => r?.pattern === route.pattern);
|
|
4502
4524
|
if (!bundledRoute)
|
|
4503
|
-
|
|
4525
|
+
return null;
|
|
4504
4526
|
const ssr = bundledRoute?.ssr;
|
|
4505
4527
|
const dataFn = ssr?.data;
|
|
4506
4528
|
if (typeof dataFn === "function") {
|
|
@@ -4513,21 +4535,33 @@ async function discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfi
|
|
|
4513
4535
|
});
|
|
4514
4536
|
const items = extractRSSItemsFromData(result, route.pattern, baseUrl, rssConfig);
|
|
4515
4537
|
if (items.length > 0) {
|
|
4516
|
-
|
|
4538
|
+
return { pattern: route.pattern, items };
|
|
4517
4539
|
}
|
|
4518
4540
|
} catch {}
|
|
4519
4541
|
}
|
|
4542
|
+
return null;
|
|
4543
|
+
});
|
|
4544
|
+
const results = await Promise.all(routePromises);
|
|
4545
|
+
for (const result of results) {
|
|
4546
|
+
if (result) {
|
|
4547
|
+
ssrDataFeeds.set(result.pattern, result.items);
|
|
4548
|
+
}
|
|
4520
4549
|
}
|
|
4521
4550
|
} else {
|
|
4522
|
-
const
|
|
4523
|
-
const { staticRoutes } = await discoverRoutes2(cwd, isWatchMode);
|
|
4524
|
-
for (const route of staticRoutes) {
|
|
4551
|
+
const routePromises = staticRoutes.map(async (route) => {
|
|
4525
4552
|
if (rssConfig?.excludeDiscovery?.some((excluded) => route.pattern.startsWith(excluded))) {
|
|
4526
|
-
|
|
4553
|
+
return null;
|
|
4527
4554
|
}
|
|
4528
4555
|
const items = await discoverSSRDataFeedItems(cwd, route.pattern, route.path, isWatchMode, baseUrl, rssConfig);
|
|
4529
4556
|
if (items.length > 0) {
|
|
4530
|
-
|
|
4557
|
+
return { pattern: route.pattern, items };
|
|
4558
|
+
}
|
|
4559
|
+
return null;
|
|
4560
|
+
});
|
|
4561
|
+
const results = await Promise.all(routePromises);
|
|
4562
|
+
for (const result of results) {
|
|
4563
|
+
if (result) {
|
|
4564
|
+
ssrDataFeeds.set(result.pattern, result.items);
|
|
4531
4565
|
}
|
|
4532
4566
|
}
|
|
4533
4567
|
}
|
|
@@ -6042,6 +6076,8 @@ let hasConnected = false;
|
|
|
6042
6076
|
let wasDisconnected = false;
|
|
6043
6077
|
let reloadTriggered = false;
|
|
6044
6078
|
let rebuildNotice = null;
|
|
6079
|
+
let reconnectAttempts = 0;
|
|
6080
|
+
let isReconnecting = false;
|
|
6045
6081
|
|
|
6046
6082
|
function showRebuildNotice() {
|
|
6047
6083
|
if (rebuildNotice) return;
|
|
@@ -6119,6 +6155,43 @@ function hideRebuildNotice() {
|
|
|
6119
6155
|
}
|
|
6120
6156
|
}
|
|
6121
6157
|
|
|
6158
|
+
// Check if server is ready before attempting SSE connection
|
|
6159
|
+
async function waitForServer() {
|
|
6160
|
+
const maxAttempts = 60; // 30 seconds max
|
|
6161
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
6162
|
+
try {
|
|
6163
|
+
const res = await fetch('/__reroute_watch.js', { method: 'HEAD' });
|
|
6164
|
+
if (res.ok) return true;
|
|
6165
|
+
} catch {
|
|
6166
|
+
// Server not ready, continue waiting
|
|
6167
|
+
}
|
|
6168
|
+
await new Promise(r => setTimeout(r, 500));
|
|
6169
|
+
}
|
|
6170
|
+
return false;
|
|
6171
|
+
}
|
|
6172
|
+
|
|
6173
|
+
async function scheduleReconnect() {
|
|
6174
|
+
if (reloadTriggered || isReconnecting) return;
|
|
6175
|
+
isReconnecting = true;
|
|
6176
|
+
|
|
6177
|
+
// Exponential backoff: 300ms, 600ms, 1200ms, max 2000ms
|
|
6178
|
+
const delay = Math.min(300 * Math.pow(2, reconnectAttempts), 2000);
|
|
6179
|
+
reconnectAttempts++;
|
|
6180
|
+
|
|
6181
|
+
await new Promise(r => setTimeout(r, delay));
|
|
6182
|
+
|
|
6183
|
+
// Wait for server to be ready before creating EventSource
|
|
6184
|
+
const ready = await waitForServer();
|
|
6185
|
+
isReconnecting = false;
|
|
6186
|
+
|
|
6187
|
+
if (ready && !reloadTriggered) {
|
|
6188
|
+
connect();
|
|
6189
|
+
} else if (!reloadTriggered) {
|
|
6190
|
+
// Server still not ready, try again
|
|
6191
|
+
scheduleReconnect();
|
|
6192
|
+
}
|
|
6193
|
+
}
|
|
6194
|
+
|
|
6122
6195
|
function connect() {
|
|
6123
6196
|
if (reloadTriggered) return;
|
|
6124
6197
|
|
|
@@ -6126,6 +6199,7 @@ function connect() {
|
|
|
6126
6199
|
|
|
6127
6200
|
eventSource.addEventListener('message', (e) => {
|
|
6128
6201
|
if (e.data === 'connected') {
|
|
6202
|
+
reconnectAttempts = 0; // Reset backoff on successful connection
|
|
6129
6203
|
if (hasConnected && wasDisconnected && !reloadTriggered) {
|
|
6130
6204
|
console.log('[reroute] ✓ Server restarted, reloading...');
|
|
6131
6205
|
reloadTriggered = true;
|
|
@@ -6149,11 +6223,12 @@ function connect() {
|
|
|
6149
6223
|
if (reloadTriggered) return;
|
|
6150
6224
|
wasDisconnected = true;
|
|
6151
6225
|
eventSource?.close();
|
|
6152
|
-
if (hasConnected) {
|
|
6226
|
+
if (hasConnected && reconnectAttempts === 0) {
|
|
6227
|
+
// Only log on first disconnect to reduce console spam
|
|
6153
6228
|
console.log('[reroute] \uD83D\uDD04 Server restarting...');
|
|
6154
6229
|
showRebuildNotice();
|
|
6155
6230
|
}
|
|
6156
|
-
|
|
6231
|
+
scheduleReconnect();
|
|
6157
6232
|
});
|
|
6158
6233
|
}
|
|
6159
6234
|
|
|
@@ -6776,6 +6851,7 @@ function registerOGRoutes(app, options) {
|
|
|
6776
6851
|
const width = ogConfig.width ?? 1200;
|
|
6777
6852
|
const height = ogConfig.height ?? 630;
|
|
6778
6853
|
const maxAge = ogConfig.maxAge ?? 3600;
|
|
6854
|
+
const generatingImages = new Set;
|
|
6779
6855
|
function normalizeOgPathname(urlPathname) {
|
|
6780
6856
|
let pathname = urlPathname.replace(/^\/__reroute_og/, "").replace(/\.png$/, "");
|
|
6781
6857
|
if (pathname === "/index" || pathname === "index") {
|
|
@@ -6797,7 +6873,7 @@ function registerOGRoutes(app, options) {
|
|
|
6797
6873
|
}
|
|
6798
6874
|
return;
|
|
6799
6875
|
}
|
|
6800
|
-
async function generateOgImage(pathname, clientDir2, cwd2, isWatchMode2, ogConfig2, width2, height2
|
|
6876
|
+
async function generateOgImage(pathname, clientDir2, cwd2, isWatchMode2, ogConfig2, width2, height2) {
|
|
6801
6877
|
const ogPath = await findOGImageForPath(pathname, clientDir2);
|
|
6802
6878
|
const Component = await loadOgComponent(ogPath, ogConfig2, cwd2, isWatchMode2);
|
|
6803
6879
|
if (!Component) {
|
|
@@ -6867,10 +6943,6 @@ function registerOGRoutes(app, options) {
|
|
|
6867
6943
|
if (maxAge > 0) {
|
|
6868
6944
|
ogCache.set(pathname, { buffer, exp: Date.now() + maxAge * 1000 });
|
|
6869
6945
|
}
|
|
6870
|
-
set.headers["content-type"] = "image/png";
|
|
6871
|
-
set.headers["cache-control"] = `public, max-age=${maxAge}`;
|
|
6872
|
-
set.headers["Reroute-Cache"] = "MISS";
|
|
6873
|
-
return new Response(buffer);
|
|
6874
6946
|
}
|
|
6875
6947
|
app.get("/__reroute_og/*", async ({ request, set }) => {
|
|
6876
6948
|
try {
|
|
@@ -6879,9 +6951,30 @@ function registerOGRoutes(app, options) {
|
|
|
6879
6951
|
const cachedResponse = checkOgCache(pathname, set);
|
|
6880
6952
|
if (cachedResponse)
|
|
6881
6953
|
return cachedResponse;
|
|
6882
|
-
|
|
6954
|
+
if (generatingImages.has(pathname)) {
|
|
6955
|
+
set.status = 404;
|
|
6956
|
+
set.headers["Retry-After"] = "2";
|
|
6957
|
+
return new Response("Image generation in progress", {
|
|
6958
|
+
status: 404,
|
|
6959
|
+
headers: { "Content-Type": "text/plain" }
|
|
6960
|
+
});
|
|
6961
|
+
}
|
|
6962
|
+
generatingImages.add(pathname);
|
|
6963
|
+
generateOgImage(pathname, clientDir, cwd, isWatchMode, ogConfig, width, height).then(() => {
|
|
6964
|
+
console.log(`[reroute/og] Generated image for: ${pathname}`);
|
|
6965
|
+
}).catch((error) => {
|
|
6966
|
+
console.error(`[reroute/og] Failed to generate image for ${pathname}:`, error);
|
|
6967
|
+
}).finally(() => {
|
|
6968
|
+
generatingImages.delete(pathname);
|
|
6969
|
+
});
|
|
6970
|
+
set.status = 404;
|
|
6971
|
+
set.headers["Retry-After"] = "2";
|
|
6972
|
+
return new Response("Image not yet available, please retry", {
|
|
6973
|
+
status: 404,
|
|
6974
|
+
headers: { "Content-Type": "text/plain" }
|
|
6975
|
+
});
|
|
6883
6976
|
} catch (error) {
|
|
6884
|
-
console.error("[reroute] Failed to
|
|
6977
|
+
console.error("[reroute] Failed to handle OG image request:", error);
|
|
6885
6978
|
set.status = 500;
|
|
6886
6979
|
return new Response("Internal Server Error", {
|
|
6887
6980
|
status: 500,
|
|
@@ -7025,6 +7118,23 @@ function registerRobotsRoute(app, options) {
|
|
|
7025
7118
|
// packages/elysia/src/routes/rss.ts
|
|
7026
7119
|
init_core();
|
|
7027
7120
|
import { NotFoundError as NotFoundError8 } from "elysia";
|
|
7121
|
+
var rssDiscoveryCache = new LRUCache(1);
|
|
7122
|
+
async function getOrDiscoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig) {
|
|
7123
|
+
if (isWatchMode) {
|
|
7124
|
+
return discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
|
|
7125
|
+
}
|
|
7126
|
+
const cacheKey = "rss:discovery";
|
|
7127
|
+
const cached = rssDiscoveryCache.get(cacheKey);
|
|
7128
|
+
if (cached && cached.exp > Date.now()) {
|
|
7129
|
+
return cached.discovery;
|
|
7130
|
+
}
|
|
7131
|
+
const discovery5 = await discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
|
|
7132
|
+
rssDiscoveryCache.set(cacheKey, {
|
|
7133
|
+
discovery: discovery5,
|
|
7134
|
+
exp: Date.now() + 5 * 60 * 1000
|
|
7135
|
+
});
|
|
7136
|
+
return discovery5;
|
|
7137
|
+
}
|
|
7028
7138
|
function createFeedTitle(configTitle, name) {
|
|
7029
7139
|
return configTitle ?? `${name.charAt(0).toUpperCase() + name.slice(1)} Feed`;
|
|
7030
7140
|
}
|
|
@@ -7055,7 +7165,7 @@ async function registerMainFeedRoute(app, cwd, collections2, baseUrl, isWatchMod
|
|
|
7055
7165
|
if (cached) {
|
|
7056
7166
|
return feedResponse(cached.xml, format, { maxAge, cacheStatus: "HIT" });
|
|
7057
7167
|
}
|
|
7058
|
-
const discovery5 = await
|
|
7168
|
+
const discovery5 = await getOrDiscoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
|
|
7059
7169
|
const allItems = [
|
|
7060
7170
|
...Array.from(discovery5.collections.values()).flat(),
|
|
7061
7171
|
...Array.from(discovery5.ssrDataFeeds.values()).flat()
|
|
@@ -7094,7 +7204,7 @@ function registerCollectionFeedRoutes(app, collections2, options) {
|
|
|
7094
7204
|
cacheStatus: "HIT"
|
|
7095
7205
|
});
|
|
7096
7206
|
}
|
|
7097
|
-
const discovery5 = await
|
|
7207
|
+
const discovery5 = await getOrDiscoverRSSData(options.cwd, [collection], options.baseUrl, options.isWatchMode, options.rssConfig);
|
|
7098
7208
|
const items = discovery5.collections.get(collection) ?? [];
|
|
7099
7209
|
if (items.length === 0)
|
|
7100
7210
|
throw new NotFoundError8;
|
|
@@ -7155,7 +7265,7 @@ async function generateSSRDataFeed(route, options) {
|
|
|
7155
7265
|
}
|
|
7156
7266
|
let items = await discoverSSRDataFeedItems(options.cwd, route.pattern, route.path, options.isWatchMode, options.baseUrl, options.rssConfig);
|
|
7157
7267
|
if (items.length === 0 && route.isLayout) {
|
|
7158
|
-
const discovery5 = await
|
|
7268
|
+
const discovery5 = await getOrDiscoverRSSData(options.cwd, [], options.baseUrl, options.isWatchMode, options.rssConfig);
|
|
7159
7269
|
items = discovery5.ssrDataFeeds.get(route.pattern) ?? [];
|
|
7160
7270
|
}
|
|
7161
7271
|
if (items.length === 0)
|
|
@@ -7212,7 +7322,6 @@ async function registerRSSRoutes(app, options) {
|
|
|
7212
7322
|
const feedDescription = rssConfig?.description ?? "Latest updates";
|
|
7213
7323
|
const availableFeeds = ["/feed.xml"];
|
|
7214
7324
|
registerMainFeedRoute(app, cwd, collections2, baseUrl, isWatchMode, rssCache, format, limit, maxAge, ttlMs, feedTitle, feedDescription, rssConfig);
|
|
7215
|
-
const ssrDataRoutes = await discoverSSRRoutes(cwd, isWatchMode);
|
|
7216
7325
|
registerCollectionFeedRoutes(app, collections2, {
|
|
7217
7326
|
cwd,
|
|
7218
7327
|
clientDir,
|
|
@@ -7226,6 +7335,11 @@ async function registerRSSRoutes(app, options) {
|
|
|
7226
7335
|
rssConfig,
|
|
7227
7336
|
availableFeeds
|
|
7228
7337
|
});
|
|
7338
|
+
if (isWatchMode) {
|
|
7339
|
+
globalThis.__REROUTE_AVAILABLE_FEEDS__ = availableFeeds;
|
|
7340
|
+
return app;
|
|
7341
|
+
}
|
|
7342
|
+
const ssrDataRoutes = await discoverSSRRoutes(cwd, isWatchMode);
|
|
7229
7343
|
const routesWithFeeds = await discoverRoutesWithFeeds(ssrDataRoutes, collections2, {
|
|
7230
7344
|
cwd,
|
|
7231
7345
|
clientDir,
|
|
@@ -7376,9 +7490,26 @@ function registerSearchRoute(app, cwd, directive, maxAge, searchConfig) {
|
|
|
7376
7490
|
// packages/elysia/src/routes/sitemap.ts
|
|
7377
7491
|
init_core();
|
|
7378
7492
|
import { NotFoundError as NotFoundError9 } from "elysia";
|
|
7493
|
+
var sitemapDiscoveryCache = new LRUCache(1);
|
|
7494
|
+
async function getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig) {
|
|
7495
|
+
if (isWatchMode) {
|
|
7496
|
+
return discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
|
|
7497
|
+
}
|
|
7498
|
+
const cacheKey = "sitemap:discovery";
|
|
7499
|
+
const cached = sitemapDiscoveryCache.get(cacheKey);
|
|
7500
|
+
if (cached && cached.exp > Date.now()) {
|
|
7501
|
+
return cached.discovery;
|
|
7502
|
+
}
|
|
7503
|
+
const discovery5 = await discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
|
|
7504
|
+
sitemapDiscoveryCache.set(cacheKey, {
|
|
7505
|
+
discovery: discovery5,
|
|
7506
|
+
exp: Date.now() + 5 * 60 * 1000
|
|
7507
|
+
});
|
|
7508
|
+
return discovery5;
|
|
7509
|
+
}
|
|
7379
7510
|
async function generateAndCacheSitemap(options, _ttlMs) {
|
|
7380
7511
|
const { cwd, collections: collections2, baseUrl, isWatchMode, sitemapConfig } = options;
|
|
7381
|
-
const discovery5 = await
|
|
7512
|
+
const discovery5 = await getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
|
|
7382
7513
|
const result = await generateSitemap(discovery5, baseUrl, {
|
|
7383
7514
|
changefreq: sitemapConfig?.changefreq,
|
|
7384
7515
|
priority: sitemapConfig?.priority,
|
|
@@ -8107,8 +8238,24 @@ var reroute = () => async (app) => {
|
|
|
8107
8238
|
const shouldIgnore = !ignorePatterns.length ? () => false : (file) => ignorePatterns.find((pattern) => typeof pattern === "string" ? file.includes(pattern) : pattern.test(file));
|
|
8108
8239
|
const isWatchMode = Array.isArray(process.execArgv) && process.execArgv.includes("--watch") || Array.isArray(process.argv) && process.argv.includes("--watch");
|
|
8109
8240
|
const dataCacheControl = `${directive}, max-age=${maxAge}`;
|
|
8110
|
-
if (isWatchMode)
|
|
8241
|
+
if (isWatchMode) {
|
|
8111
8242
|
console.log(`[reroute] Live reload enabled`);
|
|
8243
|
+
registerLiveReloadRoutes(app, liveReloadState);
|
|
8244
|
+
app.post("/__reroute_rebuilding", () => {
|
|
8245
|
+
console.log("[reroute] Rebuild notification received, notifying browsers...");
|
|
8246
|
+
notifyRebuilding();
|
|
8247
|
+
return new Response(JSON.stringify({ ok: true, clients: liveReloadState.clients.size }), {
|
|
8248
|
+
headers: { "content-type": "application/json" }
|
|
8249
|
+
});
|
|
8250
|
+
});
|
|
8251
|
+
app.post("/__reroute_reload", () => {
|
|
8252
|
+
console.log(`[reroute] Reload notification received, notifying ${liveReloadState.clients.size} browser(s)...`);
|
|
8253
|
+
notifyReload();
|
|
8254
|
+
return new Response(JSON.stringify({ ok: true, clients: liveReloadState.clients.size }), {
|
|
8255
|
+
headers: { "content-type": "application/json" }
|
|
8256
|
+
});
|
|
8257
|
+
});
|
|
8258
|
+
}
|
|
8112
8259
|
const readBundleUrl = async () => {
|
|
8113
8260
|
const bundlesDir = `${cwd}/.reroute/bundles`;
|
|
8114
8261
|
const maxAttempts = isWatchMode ? 500 : 10;
|
|
@@ -8155,25 +8302,6 @@ var reroute = () => async (app) => {
|
|
|
8155
8302
|
isWatchMode,
|
|
8156
8303
|
maxAge
|
|
8157
8304
|
});
|
|
8158
|
-
if (isWatchMode) {
|
|
8159
|
-
registerLiveReloadRoutes(app, liveReloadState);
|
|
8160
|
-
}
|
|
8161
|
-
if (isWatchMode) {
|
|
8162
|
-
app.post("/__reroute_rebuilding", () => {
|
|
8163
|
-
console.log("[reroute] Rebuild notification received, notifying browsers...");
|
|
8164
|
-
notifyRebuilding();
|
|
8165
|
-
return new Response(JSON.stringify({ ok: true, clients: liveReloadState.clients.size }), {
|
|
8166
|
-
headers: { "content-type": "application/json" }
|
|
8167
|
-
});
|
|
8168
|
-
});
|
|
8169
|
-
app.post("/__reroute_reload", () => {
|
|
8170
|
-
console.log(`[reroute] Reload notification received, notifying ${liveReloadState.clients.size} browser(s)...`);
|
|
8171
|
-
notifyReload();
|
|
8172
|
-
return new Response(JSON.stringify({ ok: true, clients: liveReloadState.clients.size }), {
|
|
8173
|
-
headers: { "content-type": "application/json" }
|
|
8174
|
-
});
|
|
8175
|
-
});
|
|
8176
|
-
}
|
|
8177
8305
|
registerArtifactsRoutes(app, cwd, fileCache, {
|
|
8178
8306
|
bundleMaxAge,
|
|
8179
8307
|
directive,
|
|
@@ -8222,6 +8350,39 @@ var reroute = () => async (app) => {
|
|
|
8222
8350
|
console.error("[reroute] Failed to register robots route:", error);
|
|
8223
8351
|
}
|
|
8224
8352
|
}
|
|
8353
|
+
if (sitemapEnabled && sitemapBaseUrl) {
|
|
8354
|
+
try {
|
|
8355
|
+
registerSitemapRoutes(app, {
|
|
8356
|
+
cwd,
|
|
8357
|
+
collections: collections2,
|
|
8358
|
+
baseUrl: sitemapBaseUrl,
|
|
8359
|
+
maxAge,
|
|
8360
|
+
isWatchMode,
|
|
8361
|
+
sitemapCache,
|
|
8362
|
+
sitemapConfig
|
|
8363
|
+
});
|
|
8364
|
+
console.log(`[reroute] Sitemap enabled at ${sitemapBaseUrl}/sitemap.xml`);
|
|
8365
|
+
} catch (error) {
|
|
8366
|
+
console.error("[reroute] Failed to register sitemap routes:", error);
|
|
8367
|
+
}
|
|
8368
|
+
}
|
|
8369
|
+
if (rssEnabled && rssBaseUrl) {
|
|
8370
|
+
try {
|
|
8371
|
+
await registerRSSRoutes(app, {
|
|
8372
|
+
cwd,
|
|
8373
|
+
clientDir,
|
|
8374
|
+
collections: collections2,
|
|
8375
|
+
baseUrl: rssBaseUrl,
|
|
8376
|
+
maxAge,
|
|
8377
|
+
isWatchMode,
|
|
8378
|
+
rssCache,
|
|
8379
|
+
rssConfig
|
|
8380
|
+
});
|
|
8381
|
+
console.log(`[reroute] RSS feeds enabled at ${rssBaseUrl}/feed.xml`);
|
|
8382
|
+
} catch (error) {
|
|
8383
|
+
console.error("[reroute] Failed to register RSS routes:", error);
|
|
8384
|
+
}
|
|
8385
|
+
}
|
|
8225
8386
|
if (llmsEnabled && llmsConfig) {
|
|
8226
8387
|
try {
|
|
8227
8388
|
registerLLMsRoutes(app, {
|
|
@@ -8252,6 +8413,20 @@ var reroute = () => async (app) => {
|
|
|
8252
8413
|
console.error("[reroute] Failed to register LLMs routes:", error);
|
|
8253
8414
|
}
|
|
8254
8415
|
}
|
|
8416
|
+
if (ogEnabled && ogConfig) {
|
|
8417
|
+
try {
|
|
8418
|
+
registerOGRoutes(app, {
|
|
8419
|
+
clientDir,
|
|
8420
|
+
cwd,
|
|
8421
|
+
isWatchMode,
|
|
8422
|
+
ogConfig,
|
|
8423
|
+
ogCache
|
|
8424
|
+
});
|
|
8425
|
+
console.log("[reroute] OG image generation enabled");
|
|
8426
|
+
} catch (error) {
|
|
8427
|
+
console.error("[reroute] Failed to register OG routes:", error);
|
|
8428
|
+
}
|
|
8429
|
+
}
|
|
8255
8430
|
registerSSRRoutes(app, {
|
|
8256
8431
|
rootComponent,
|
|
8257
8432
|
clientDir,
|
|
@@ -8275,53 +8450,6 @@ var reroute = () => async (app) => {
|
|
|
8275
8450
|
baseUrl,
|
|
8276
8451
|
autoCanonical
|
|
8277
8452
|
});
|
|
8278
|
-
if (sitemapEnabled && sitemapBaseUrl) {
|
|
8279
|
-
try {
|
|
8280
|
-
registerSitemapRoutes(app, {
|
|
8281
|
-
cwd,
|
|
8282
|
-
collections: collections2,
|
|
8283
|
-
baseUrl: sitemapBaseUrl,
|
|
8284
|
-
maxAge,
|
|
8285
|
-
isWatchMode,
|
|
8286
|
-
sitemapCache,
|
|
8287
|
-
sitemapConfig
|
|
8288
|
-
});
|
|
8289
|
-
console.log(`[reroute] Sitemap enabled at ${sitemapBaseUrl}/sitemap.xml`);
|
|
8290
|
-
} catch (error) {
|
|
8291
|
-
console.error("[reroute] Failed to register sitemap routes:", error);
|
|
8292
|
-
}
|
|
8293
|
-
}
|
|
8294
|
-
if (rssEnabled && rssBaseUrl) {
|
|
8295
|
-
try {
|
|
8296
|
-
await registerRSSRoutes(app, {
|
|
8297
|
-
cwd,
|
|
8298
|
-
clientDir,
|
|
8299
|
-
collections: collections2,
|
|
8300
|
-
baseUrl: rssBaseUrl,
|
|
8301
|
-
maxAge,
|
|
8302
|
-
isWatchMode,
|
|
8303
|
-
rssCache,
|
|
8304
|
-
rssConfig
|
|
8305
|
-
});
|
|
8306
|
-
console.log(`[reroute] RSS feeds enabled at ${rssBaseUrl}/feed.xml`);
|
|
8307
|
-
} catch (error) {
|
|
8308
|
-
console.error("[reroute] Failed to register RSS routes:", error);
|
|
8309
|
-
}
|
|
8310
|
-
}
|
|
8311
|
-
if (ogEnabled && ogConfig) {
|
|
8312
|
-
try {
|
|
8313
|
-
registerOGRoutes(app, {
|
|
8314
|
-
clientDir,
|
|
8315
|
-
cwd,
|
|
8316
|
-
isWatchMode,
|
|
8317
|
-
ogConfig,
|
|
8318
|
-
ogCache
|
|
8319
|
-
});
|
|
8320
|
-
console.log("[reroute] OG image generation enabled");
|
|
8321
|
-
} catch (error) {
|
|
8322
|
-
console.error("[reroute] Failed to register OG routes:", error);
|
|
8323
|
-
}
|
|
8324
|
-
}
|
|
8325
8453
|
} catch (error) {
|
|
8326
8454
|
console.error("[reroute] Failed to register SSR routes:", error);
|
|
8327
8455
|
throw error;
|
|
@@ -8342,4 +8470,4 @@ export {
|
|
|
8342
8470
|
reroute
|
|
8343
8471
|
};
|
|
8344
8472
|
|
|
8345
|
-
//# debugId=
|
|
8473
|
+
//# debugId=8F66BA5867641AA764756E2164756E21
|