reroute-js 0.2.2 → 0.3.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/README.md +14 -0
- package/_/README.md +59 -0
- package/_/basic/package.json +24 -0
- package/_/basic/src/client/App.tsx +10 -0
- package/_/basic/src/client/components/Counter.tsx +15 -0
- package/_/basic/src/client/index.html +12 -0
- package/_/basic/src/client/index.tsx +5 -0
- package/_/basic/src/client/routes/[404].tsx +18 -0
- package/_/basic/src/client/routes/about.tsx +25 -0
- package/_/basic/src/client/routes/index.tsx +57 -0
- package/_/basic/src/index.ts +20 -0
- package/_/basic/tsconfig.json +26 -0
- package/_/blog/package.json +24 -0
- package/_/blog/src/client/App.tsx +10 -0
- package/_/blog/src/client/components/Counter.tsx +14 -0
- package/_/blog/src/client/components/RecentPosts.tsx +90 -0
- package/_/blog/src/client/index.html +13 -0
- package/_/blog/src/client/index.tsx +5 -0
- package/_/blog/src/client/routes/[404].tsx +21 -0
- package/_/blog/src/client/routes/about.tsx +31 -0
- package/_/blog/src/client/routes/blog/[404].tsx +21 -0
- package/_/blog/src/client/routes/blog/[layout].tsx +84 -0
- package/_/blog/src/client/routes/blog/[slug].tsx +11 -0
- package/_/blog/src/client/routes/blog/content/1-hello-world.tsx +27 -0
- package/_/blog/src/client/routes/blog/content/2-what-is-reroute.tsx +31 -0
- package/_/blog/src/client/routes/blog/index.tsx +70 -0
- package/_/blog/src/client/routes/index.tsx +63 -0
- package/_/blog/src/index.ts +20 -0
- package/_/blog/tsconfig.json +26 -0
- package/_/store/package.json +26 -0
- package/_/store/src/client/App.tsx +17 -0
- package/_/store/src/client/components/Header.tsx +40 -0
- package/_/store/src/client/components/ProductCard.tsx +54 -0
- package/_/store/src/client/index.html +17 -0
- package/_/store/src/client/index.tsx +7 -0
- package/_/store/src/client/lib/api.ts +153 -0
- package/_/store/src/client/routes/[404].tsx +63 -0
- package/_/store/src/client/routes/categories/[category].tsx +223 -0
- package/_/store/src/client/routes/categories/index.tsx +187 -0
- package/_/store/src/client/routes/index.tsx +126 -0
- package/_/store/src/client/routes/products/[id].tsx +238 -0
- package/_/store/src/client/routes/products/index.tsx +261 -0
- package/_/store/src/client/theme.css +306 -0
- package/_/store/src/index.ts +19 -0
- package/_/store/tsconfig.json +26 -0
- package/cli/bin.d.ts +11 -0
- package/cli/bin.d.ts.map +1 -0
- package/cli/bin.js +883 -0
- package/cli/bin.js.map +15 -0
- package/cli/index.d.ts +11 -0
- package/cli/index.d.ts.map +1 -0
- package/cli/index.js +113 -0
- package/cli/index.js.map +10 -0
- package/cli/src/cli.d.ts +16 -0
- package/cli/src/cli.d.ts.map +1 -0
- package/cli/src/commands/build.d.ts +16 -0
- package/cli/src/commands/build.d.ts.map +1 -0
- package/cli/src/commands/dev.d.ts +16 -0
- package/cli/src/commands/dev.d.ts.map +1 -0
- package/cli/src/commands/gen.d.ts +11 -0
- package/cli/src/commands/gen.d.ts.map +1 -0
- package/cli/src/commands/init.d.ts +16 -0
- package/cli/src/commands/init.d.ts.map +1 -0
- package/cli/src/libs/index.d.ts +11 -0
- package/cli/src/libs/index.d.ts.map +1 -0
- package/cli/src/libs/tailwind.d.ts +20 -0
- package/cli/src/libs/tailwind.d.ts.map +1 -0
- package/core/index.d.ts +11 -0
- package/core/index.d.ts.map +1 -0
- package/core/index.js +1138 -0
- package/core/index.js.map +25 -0
- package/core/src/bundler/hash.d.ts +11 -0
- package/core/src/bundler/hash.d.ts.map +1 -0
- package/core/src/bundler/index.d.ts +12 -0
- package/core/src/bundler/index.d.ts.map +1 -0
- package/core/src/bundler/transpile.d.ts +13 -0
- package/core/src/bundler/transpile.d.ts.map +1 -0
- package/core/src/content/discovery.d.ts +14 -0
- package/core/src/content/discovery.d.ts.map +1 -0
- package/core/src/content/index.d.ts +13 -0
- package/core/src/content/index.d.ts.map +1 -0
- package/core/src/content/metadata.d.ts +18 -0
- package/core/src/content/metadata.d.ts.map +1 -0
- package/core/src/content/registry.d.ts +11 -0
- package/core/src/content/registry.d.ts.map +1 -0
- package/core/src/index.d.ts +16 -0
- package/core/src/index.d.ts.map +1 -0
- package/core/src/ssr/data.d.ts +18 -0
- package/core/src/ssr/data.d.ts.map +1 -0
- package/core/src/ssr/index.d.ts +13 -0
- package/core/src/ssr/index.d.ts.map +1 -0
- package/core/src/ssr/modules.d.ts +17 -0
- package/core/src/ssr/modules.d.ts.map +1 -0
- package/core/src/ssr/render.d.ts +29 -0
- package/core/src/ssr/render.d.ts.map +1 -0
- package/core/src/ssr/seed.d.ts +11 -0
- package/core/src/ssr/seed.d.ts.map +1 -0
- package/core/src/template/html.d.ts +13 -0
- package/core/src/template/html.d.ts.map +1 -0
- package/core/src/template/index.d.ts +11 -0
- package/core/src/template/index.d.ts.map +1 -0
- package/core/src/types.d.ts +59 -0
- package/core/src/types.d.ts.map +1 -0
- package/core/src/utils/cache.d.ts +21 -0
- package/core/src/utils/cache.d.ts.map +1 -0
- package/core/src/utils/compression.d.ts +14 -0
- package/core/src/utils/compression.d.ts.map +1 -0
- package/core/src/utils/index.d.ts +14 -0
- package/core/src/utils/index.d.ts.map +1 -0
- package/core/src/utils/mime.d.ts +12 -0
- package/core/src/utils/mime.d.ts.map +1 -0
- package/core/src/utils/path.d.ts +15 -0
- package/core/src/utils/path.d.ts.map +1 -0
- package/elysia/index.d.ts +11 -0
- package/elysia/index.d.ts.map +1 -0
- package/elysia/index.js +2101 -0
- package/elysia/index.js.map +34 -0
- package/elysia/src/index.d.ts +12 -0
- package/elysia/src/index.d.ts.map +1 -0
- package/elysia/src/libs/http.d.ts +14 -0
- package/elysia/src/libs/http.d.ts.map +1 -0
- package/elysia/src/libs/image.d.ts +38 -0
- package/elysia/src/libs/image.d.ts.map +1 -0
- package/elysia/src/plugin.d.ts +41 -0
- package/elysia/src/plugin.d.ts.map +1 -0
- package/elysia/src/routes/artifacts.d.ts +12 -0
- package/elysia/src/routes/artifacts.d.ts.map +1 -0
- package/elysia/src/routes/content.d.ts +12 -0
- package/elysia/src/routes/content.d.ts.map +1 -0
- package/elysia/src/routes/dev.d.ts +18 -0
- package/elysia/src/routes/dev.d.ts.map +1 -0
- package/elysia/src/routes/image.d.ts +23 -0
- package/elysia/src/routes/image.d.ts.map +1 -0
- package/elysia/src/routes/ssr.d.ts +32 -0
- package/elysia/src/routes/ssr.d.ts.map +1 -0
- package/elysia/src/routes/static.d.ts +28 -0
- package/elysia/src/routes/static.d.ts.map +1 -0
- package/elysia/src/types.d.ts +44 -0
- package/elysia/src/types.d.ts.map +1 -0
- package/package.json +6 -5
- package/react/index.d.ts +11 -0
- package/react/index.d.ts.map +1 -0
- package/react/index.js +1370 -0
- package/react/index.js.map +24 -0
- package/react/src/components/ContentRoute.d.ts +22 -0
- package/react/src/components/ContentRoute.d.ts.map +1 -0
- package/react/src/components/Image.d.ts +53 -0
- package/react/src/components/Image.d.ts.map +1 -0
- package/react/src/components/Link.d.ts +17 -0
- package/react/src/components/Link.d.ts.map +1 -0
- package/react/src/components/Outlet.d.ts +16 -0
- package/react/src/components/Outlet.d.ts.map +1 -0
- package/react/src/components/index.d.ts +14 -0
- package/react/src/components/index.d.ts.map +1 -0
- package/react/src/hooks/index.d.ts +16 -0
- package/react/src/hooks/index.d.ts.map +1 -0
- package/react/src/hooks/useContent.d.ts +35 -0
- package/react/src/hooks/useContent.d.ts.map +1 -0
- package/react/src/hooks/useData.d.ts +19 -0
- package/react/src/hooks/useData.d.ts.map +1 -0
- package/react/src/hooks/useNavigate.d.ts +15 -0
- package/react/src/hooks/useNavigate.d.ts.map +1 -0
- package/react/src/hooks/useParams.d.ts +15 -0
- package/react/src/hooks/useParams.d.ts.map +1 -0
- package/react/src/hooks/useRouter.d.ts +16 -0
- package/react/src/hooks/useRouter.d.ts.map +1 -0
- package/react/src/hooks/useSearchParams.d.ts +15 -0
- package/react/src/hooks/useSearchParams.d.ts.map +1 -0
- package/react/src/index.d.ts +15 -0
- package/react/src/index.d.ts.map +1 -0
- package/react/src/providers/ContentProvider.d.ts +44 -0
- package/react/src/providers/ContentProvider.d.ts.map +1 -0
- package/react/src/providers/RerouteProvider.d.ts +34 -0
- package/react/src/providers/RerouteProvider.d.ts.map +1 -0
- package/react/src/providers/RouterProvider.d.ts +32 -0
- package/react/src/providers/RouterProvider.d.ts.map +1 -0
- package/react/src/providers/index.d.ts +13 -0
- package/react/src/providers/index.d.ts.map +1 -0
- package/react/src/types/any.d.ts +12 -0
- package/react/src/types/any.d.ts.map +1 -0
- package/react/src/types/index.d.ts +12 -0
- package/react/src/types/index.d.ts.map +1 -0
- package/react/src/types/router.d.ts +41 -0
- package/react/src/types/router.d.ts.map +1 -0
- package/react/src/utils/content.d.ts +17 -0
- package/react/src/utils/content.d.ts.map +1 -0
- package/react/src/utils/head.d.ts +15 -0
- package/react/src/utils/head.d.ts.map +1 -0
- package/react/src/utils/index.d.ts +12 -0
- package/react/src/utils/index.d.ts.map +1 -0
- package/CHANGELOG.md +0 -29
- package/packages/cli/README.md +0 -264
- package/packages/cli/bin.ts +0 -3
- package/packages/core/README.md +0 -90
- package/packages/elysia/README.md +0 -250
- package/packages/react/README.md +0 -3
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
# Reroute Elysia
|
|
2
|
-
|
|
3
|
-
Elysia adapter for the Reroute framework. This package provides an Elysia plugin that enables server-side rendering, static file serving, content management, and live reload for React applications.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
This package is a thin adapter layer that integrates Reroute's core functionality with the Elysia web framework. It handles:
|
|
8
|
-
|
|
9
|
-
- **Server-Side Rendering (SSR)**: Automatic SSR for React components
|
|
10
|
-
- **Static File Serving**: Optimized static asset delivery with compression
|
|
11
|
-
- **Content Management**: File-based content collections with automatic discovery
|
|
12
|
-
- **Live Reload**: Development mode with hot reload via SSE
|
|
13
|
-
- **TypeScript/JSX Transpilation**: On-the-fly bundling with Bun
|
|
14
|
-
- **Asset Optimization**: Content hashing, compression, and caching
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
bun add reroute-js elysia react react-dom
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Usage
|
|
23
|
-
|
|
24
|
-
### Basic Setup
|
|
25
|
-
|
|
26
|
-
```typescript
|
|
27
|
-
import { Elysia } from 'elysia';
|
|
28
|
-
import { reroute } from 'reroute-js/elysia';
|
|
29
|
-
import { createElement } from 'react';
|
|
30
|
-
import App from './App';
|
|
31
|
-
|
|
32
|
-
const app = new Elysia()
|
|
33
|
-
.use(
|
|
34
|
-
reroute({
|
|
35
|
-
app: createElement(App),
|
|
36
|
-
assets: 'src/client',
|
|
37
|
-
prefix: '/',
|
|
38
|
-
})
|
|
39
|
-
)
|
|
40
|
-
.listen(3000);
|
|
41
|
-
|
|
42
|
-
console.log(`Server running at http://localhost:3000`);
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### With Collections
|
|
46
|
-
|
|
47
|
-
Content collections are automatically discovered from your `routes` directory:
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
src/client/
|
|
51
|
-
├── routes/
|
|
52
|
-
│ ├── blog/
|
|
53
|
-
│ │ └── content/
|
|
54
|
-
│ │ ├── post-1.tsx
|
|
55
|
-
│ │ └── post-2.tsx
|
|
56
|
-
│ └── docs/
|
|
57
|
-
│ └── content/
|
|
58
|
-
│ └── guide.tsx
|
|
59
|
-
├── index.html
|
|
60
|
-
└── index.tsx
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Collections are accessible at:
|
|
64
|
-
- `/blog/post-1` - SSR rendered
|
|
65
|
-
- `/blog/post-2` - SSR rendered
|
|
66
|
-
- `/__content/blog` - JSON manifest with all blog posts
|
|
67
|
-
|
|
68
|
-
## API
|
|
69
|
-
|
|
70
|
-
### `reroute(options: RerouteOptions)`
|
|
71
|
-
|
|
72
|
-
Creates an Elysia plugin with the provided configuration.
|
|
73
|
-
|
|
74
|
-
#### Options
|
|
75
|
-
|
|
76
|
-
##### SSR Options
|
|
77
|
-
|
|
78
|
-
- **`app?: ReactElement`** - Root React component for SSR. When provided, enables automatic SSR for all routes.
|
|
79
|
-
- **`head?: string`** - Additional HTML to inject into `<head>` (default: `''`)
|
|
80
|
-
- **`lang?: string`** - HTML document language (default: `'en'`)
|
|
81
|
-
- **`appId?: string`** - ID of the root element (default: `'root'`)
|
|
82
|
-
- **`entrypoint?: string`** - Client-side entry file (default: `'index.tsx'`)
|
|
83
|
-
|
|
84
|
-
##### Static Serving Options
|
|
85
|
-
|
|
86
|
-
- **`assets?: string`** - Assets directory path (default: `'src/client'`)
|
|
87
|
-
- **`prefix?: string`** - URL prefix for static files (default: `'/'`)
|
|
88
|
-
- **`ignorePatterns?: (string | RegExp)[]`** - Files to ignore (default: `['.DS_Store', '.git', '.env', 'index.html', /favicon\.ico/, /\.well-known/]`)
|
|
89
|
-
- **`staticHeaders?: Record<string, string>`** - Additional headers for static files
|
|
90
|
-
- **`maxAge?: number`** - Cache max-age in seconds (default: `3600`)
|
|
91
|
-
- **`directive?: string`** - Cache-Control directive (default: `'public'`)
|
|
92
|
-
- **`indexHTML?: boolean`** - Serve index.html for directories (default: `true`)
|
|
93
|
-
|
|
94
|
-
##### Build Options
|
|
95
|
-
|
|
96
|
-
- **`minify?: boolean`** - Minify JavaScript bundles (default: `process.env.NODE_ENV === 'production'`)
|
|
97
|
-
- **`sourcemap?: boolean`** - Generate sourcemaps (default: `true`)
|
|
98
|
-
|
|
99
|
-
## Features
|
|
100
|
-
|
|
101
|
-
### Automatic SSR
|
|
102
|
-
|
|
103
|
-
When you provide a root component via the `app` option, Reroute automatically:
|
|
104
|
-
|
|
105
|
-
1. Discovers content collections in your routes directory
|
|
106
|
-
2. Registers SSR routes for each collection (e.g., `/blog/*`, `/docs/*`)
|
|
107
|
-
3. Renders components on the server with React
|
|
108
|
-
4. Sends fully hydrated HTML to the client
|
|
109
|
-
5. Hydrates the client-side React app seamlessly
|
|
110
|
-
|
|
111
|
-
### Content Collections
|
|
112
|
-
|
|
113
|
-
Content files are TypeScript/TSX modules that export a React component and optional metadata:
|
|
114
|
-
|
|
115
|
-
```tsx
|
|
116
|
-
// src/client/routes/blog/content/my-post.tsx
|
|
117
|
-
export const meta = {
|
|
118
|
-
title: 'My Blog Post',
|
|
119
|
-
excerpt: 'This is a great post',
|
|
120
|
-
date: '2024-01-15',
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// Optional SSR extras per page
|
|
124
|
-
export const ssr = {
|
|
125
|
-
// Extra tags appended verbatim into <head>
|
|
126
|
-
head: [
|
|
127
|
-
'<meta property="og:type" content="article" />',
|
|
128
|
-
],
|
|
129
|
-
// Override document language for this page
|
|
130
|
-
lang: 'en',
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
export default function MyPost() {
|
|
134
|
-
return (
|
|
135
|
-
<article>
|
|
136
|
-
<h1>My Blog Post</h1>
|
|
137
|
-
<p>Content goes here...</p>
|
|
138
|
-
</article>
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
Access via:
|
|
144
|
-
- **Route**: `/blog/my-post` (SSR rendered)
|
|
145
|
-
- **API**: `/__content/blog` (JSON manifest)
|
|
146
|
-
|
|
147
|
-
During SSR, `meta.title` and `meta.description` (or `meta.excerpt`) are converted into `<title>` and `<meta name="description">`. Any `ssr.head` content is appended to `<head>`, and `ssr.lang` overrides the HTML `lang` attribute for that response.
|
|
148
|
-
|
|
149
|
-
### Development Mode
|
|
150
|
-
|
|
151
|
-
Run with `--watch` flag to enable live reload:
|
|
152
|
-
|
|
153
|
-
```bash
|
|
154
|
-
bun --watch src/server.ts
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
Features:
|
|
158
|
-
- File watching with automatic rebuild
|
|
159
|
-
- SSE-based live reload (no browser extension needed)
|
|
160
|
-
- Fast hot module replacement
|
|
161
|
-
- Source map support
|
|
162
|
-
|
|
163
|
-
### Production Optimization
|
|
164
|
-
|
|
165
|
-
In production:
|
|
166
|
-
- JavaScript bundles are minified
|
|
167
|
-
- Content is hashed for cache busting (e.g., `index.abc12345.js`)
|
|
168
|
-
- Responses are gzip compressed
|
|
169
|
-
- Aggressive caching headers for hashed assets
|
|
170
|
-
- Preloading hints for content chunks
|
|
171
|
-
|
|
172
|
-
## Routes
|
|
173
|
-
|
|
174
|
-
The Elysia plugin registers these routes automatically:
|
|
175
|
-
|
|
176
|
-
### Content Routes
|
|
177
|
-
- `/__content/:collection` - JSON manifest of collection items
|
|
178
|
-
|
|
179
|
-
### Development Routes (watch mode only)
|
|
180
|
-
- `/__reroute_watch` - SSE endpoint for live reload
|
|
181
|
-
- `/__reroute_watch.js` - Live reload client script
|
|
182
|
-
- `/__reroute_preload` - Content chunk preloader
|
|
183
|
-
|
|
184
|
-
### Artifact Routes
|
|
185
|
-
- `/.reroute/*` - Generated content chunks and bundles
|
|
186
|
-
|
|
187
|
-
### SSR Routes
|
|
188
|
-
- `/:collection/:slug` - Server-rendered collection items
|
|
189
|
-
- `/*` (fallback) - Catch-all SSR for unmatched routes
|
|
190
|
-
|
|
191
|
-
### Static Routes
|
|
192
|
-
- `${prefix}/*` - Static file serving with transpilation
|
|
193
|
-
|
|
194
|
-
## Architecture
|
|
195
|
-
|
|
196
|
-
This package is built on top of `reroute-js/core`, which provides framework-agnostic utilities. The Elysia adapter:
|
|
197
|
-
|
|
198
|
-
1. Translates Elysia request/response objects
|
|
199
|
-
2. Registers appropriate route handlers
|
|
200
|
-
3. Handles errors with Elysia's `NotFoundError`
|
|
201
|
-
4. Manages caches and live reload state
|
|
202
|
-
|
|
203
|
-
This separation allows Reroute to support multiple frameworks (Hono, Fastify, etc.) by creating similar adapter packages.
|
|
204
|
-
|
|
205
|
-
## Examples
|
|
206
|
-
|
|
207
|
-
### Custom Ignore Patterns
|
|
208
|
-
|
|
209
|
-
```typescript
|
|
210
|
-
reroute({
|
|
211
|
-
ignorePatterns: [
|
|
212
|
-
'.DS_Store',
|
|
213
|
-
/\.test\.(ts|tsx|js|jsx)$/,
|
|
214
|
-
/^_/, // Ignore files starting with underscore
|
|
215
|
-
],
|
|
216
|
-
})
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
### Custom Headers
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
reroute({
|
|
223
|
-
staticHeaders: {
|
|
224
|
-
'X-Custom-Header': 'value',
|
|
225
|
-
'Access-Control-Allow-Origin': '*',
|
|
226
|
-
},
|
|
227
|
-
})
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
### Multiple Asset Directories
|
|
231
|
-
|
|
232
|
-
You can mount multiple reroute instances with different prefixes:
|
|
233
|
-
|
|
234
|
-
```typescript
|
|
235
|
-
new Elysia()
|
|
236
|
-
.use(reroute({ assets: 'src/client', prefix: '/app' }))
|
|
237
|
-
.use(reroute({ assets: 'src/admin', prefix: '/admin' }))
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
## TypeScript
|
|
241
|
-
|
|
242
|
-
All types are exported from the package:
|
|
243
|
-
|
|
244
|
-
```typescript
|
|
245
|
-
import type { RerouteOptions } from 'reroute-js/elysia';
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
## License
|
|
249
|
-
|
|
250
|
-
MIT
|
package/packages/react/README.md
DELETED