@ressjs/vite-router 0.5.2 → 0.6.0-rc.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.
Files changed (141) hide show
  1. package/LICENSE +69 -0
  2. package/README.md +9 -515
  3. package/dist/client/entry.d.mts +2 -0
  4. package/dist/client/entry.mjs +1 -0
  5. package/dist/client/index.d.ts +2 -0
  6. package/dist/client/index.js +8 -0
  7. package/dist/config/base-path.d.ts +44 -0
  8. package/dist/config/base-path.js +100 -0
  9. package/dist/config/codegen.d.ts +29 -0
  10. package/dist/config/codegen.js +131 -0
  11. package/dist/config/define.d.ts +8 -0
  12. package/dist/config/define.js +12 -0
  13. package/dist/config/env.d.ts +19 -0
  14. package/dist/config/env.js +40 -0
  15. package/dist/config/index.d.ts +18 -0
  16. package/dist/config/index.js +46 -0
  17. package/dist/config/load.d.ts +28 -0
  18. package/dist/config/load.js +82 -0
  19. package/dist/config/middleware.d.ts +18 -0
  20. package/dist/config/middleware.js +79 -0
  21. package/dist/config/rules.d.ts +59 -0
  22. package/dist/config/rules.js +162 -0
  23. package/dist/config/types.d.ts +189 -0
  24. package/dist/config/types.js +2 -0
  25. package/dist/config/validate.d.ts +19 -0
  26. package/dist/config/validate.js +143 -0
  27. package/dist/config/watch.d.ts +53 -0
  28. package/dist/config/watch.js +163 -0
  29. package/dist/fs/module-extensions.d.ts +105 -0
  30. package/dist/fs/module-extensions.js +213 -0
  31. package/dist/head/resolve.d.ts +5 -0
  32. package/dist/head/resolve.js +166 -0
  33. package/dist/head/types.d.ts +44 -0
  34. package/dist/head/types.js +2 -0
  35. package/dist/helpers/html-generator.d.ts +26 -6
  36. package/dist/helpers/html-generator.js +96 -138
  37. package/dist/helpers/middlewares.d.ts +32 -21
  38. package/dist/helpers/middlewares.js +181 -159
  39. package/dist/helpers/page-config-merge.d.ts +11 -0
  40. package/dist/helpers/page-config-merge.js +84 -0
  41. package/dist/helpers/request-handler.d.ts +15 -2
  42. package/dist/helpers/request-handler.js +164 -27
  43. package/dist/index.d.ts +35 -3
  44. package/dist/index.js +77 -8
  45. package/dist/isr/capture.d.ts +79 -0
  46. package/dist/isr/capture.js +222 -0
  47. package/dist/isr/handler.d.ts +49 -0
  48. package/dist/isr/handler.js +207 -0
  49. package/dist/isr/key.d.ts +26 -0
  50. package/dist/isr/key.js +59 -0
  51. package/dist/isr/page-config.d.ts +17 -0
  52. package/dist/isr/page-config.js +71 -0
  53. package/dist/isr/preview.d.ts +5 -0
  54. package/dist/isr/preview.js +38 -0
  55. package/dist/isr/public-request.d.ts +50 -0
  56. package/dist/isr/public-request.js +108 -0
  57. package/dist/isr/response.d.ts +41 -0
  58. package/dist/isr/response.js +128 -0
  59. package/dist/isr/store.d.ts +42 -0
  60. package/dist/isr/store.js +108 -0
  61. package/dist/isr/types.d.ts +62 -0
  62. package/dist/isr/types.js +2 -0
  63. package/dist/pages.d.ts +10 -9
  64. package/dist/pages.js +42 -261
  65. package/dist/platform.d.ts +11 -14
  66. package/dist/platform.js +18 -102
  67. package/dist/plugin/environments.d.ts +68 -0
  68. package/dist/plugin/environments.js +74 -0
  69. package/dist/plugin/index.d.ts +59 -0
  70. package/dist/plugin/index.js +195 -0
  71. package/dist/plugin/route-manifest.d.ts +19 -0
  72. package/dist/plugin/route-manifest.js +55 -0
  73. package/dist/plugin/virtual-entries.d.ts +26 -0
  74. package/dist/plugin/virtual-entries.js +80 -0
  75. package/dist/render.d.ts +39 -2
  76. package/dist/render.js +75 -77
  77. package/dist/router.d.ts +32 -13
  78. package/dist/router.js +180 -146
  79. package/dist/routes/dispatcher.d.ts +58 -0
  80. package/dist/routes/dispatcher.js +70 -0
  81. package/dist/routes/manifest.d.ts +17 -0
  82. package/dist/routes/manifest.js +62 -0
  83. package/dist/routes/match.d.ts +20 -0
  84. package/dist/routes/match.js +75 -0
  85. package/dist/routes/module.d.ts +14 -0
  86. package/dist/routes/module.js +30 -0
  87. package/dist/routes/parse.d.ts +31 -0
  88. package/dist/routes/parse.js +114 -0
  89. package/dist/routes/rank.d.ts +12 -0
  90. package/dist/routes/rank.js +49 -0
  91. package/dist/routes/router.d.ts +54 -0
  92. package/dist/routes/router.js +153 -0
  93. package/dist/routes/scan.d.ts +26 -0
  94. package/dist/routes/scan.js +98 -0
  95. package/dist/routes/types.d.ts +114 -0
  96. package/dist/routes/types.js +17 -0
  97. package/dist/runtime/dev-server.d.ts +64 -0
  98. package/dist/runtime/dev-server.js +94 -0
  99. package/dist/runtime/dev-styles.d.ts +13 -0
  100. package/dist/runtime/dev-styles.js +50 -0
  101. package/dist/runtime/module-loader.d.ts +55 -0
  102. package/dist/runtime/module-loader.js +122 -0
  103. package/dist/runtime/prod-server.d.ts +55 -0
  104. package/dist/runtime/prod-server.js +188 -0
  105. package/dist/runtime/template.d.ts +10 -0
  106. package/dist/runtime/template.js +33 -0
  107. package/dist/security/client-props.d.ts +25 -0
  108. package/dist/security/client-props.js +51 -0
  109. package/dist/security/config.d.ts +121 -0
  110. package/dist/security/config.js +77 -0
  111. package/dist/security/csp.d.ts +53 -0
  112. package/dist/security/csp.js +118 -0
  113. package/dist/security/dev-hardening.d.ts +46 -0
  114. package/dist/security/dev-hardening.js +65 -0
  115. package/dist/security/errors.d.ts +37 -0
  116. package/dist/security/errors.js +84 -0
  117. package/dist/security/escape.d.ts +40 -0
  118. package/dist/security/escape.js +90 -0
  119. package/dist/security/head-tags.d.ts +32 -0
  120. package/dist/security/head-tags.js +156 -0
  121. package/dist/security/headers.d.ts +76 -0
  122. package/dist/security/headers.js +278 -0
  123. package/dist/security/index.d.ts +24 -0
  124. package/dist/security/index.js +49 -0
  125. package/dist/security/serialize.d.ts +48 -0
  126. package/dist/security/serialize.js +146 -0
  127. package/dist/variants/assets.d.ts +33 -0
  128. package/dist/variants/assets.js +144 -0
  129. package/dist/variants/catalog.d.ts +33 -0
  130. package/dist/variants/catalog.js +79 -0
  131. package/dist/variants/platform-tokens.d.ts +9 -0
  132. package/dist/variants/platform-tokens.js +15 -0
  133. package/dist/variants/resolve.d.ts +40 -0
  134. package/dist/variants/resolve.js +90 -0
  135. package/dist/variants/suffix.d.ts +8 -0
  136. package/dist/variants/suffix.js +12 -0
  137. package/dist/variants/types.d.ts +72 -0
  138. package/dist/variants/types.js +2 -0
  139. package/package.json +23 -11
  140. package/dist/helpers/vite-config.d.ts +0 -10
  141. package/dist/helpers/vite-config.js +0 -90
package/LICENSE ADDED
@@ -0,0 +1,69 @@
1
+ ress.js Proprietary License
2
+
3
+ Copyright (c) 2025-2026 gabrielspisso. All rights reserved.
4
+
5
+ This license applies to the ress.js packages (the "Software"), published on npm
6
+ under the @ressjs and @gzzy scopes, in every version released from 0.6.0-rc.0
7
+ onwards. Earlier versions were released under the MIT License and remain
8
+ available under those terms.
9
+
10
+ 1. GRANT
11
+ Subject to this license, the Licensor grants you a worldwide, non-exclusive,
12
+ non-transferable, non-sublicensable, royalty-free license to install and use
13
+ the Software, as distributed by the Licensor, to build, run and deploy your
14
+ own applications and services, including commercial ones, and to charge your
15
+ own customers for them.
16
+
17
+ 2. RESTRICTIONS
18
+ You may not:
19
+ a) fork, copy, or redistribute the Software, in whole or in part, except for
20
+ the portions that are necessarily included in the build output of your own
21
+ application in order to run it;
22
+ b) publish, distribute or make available a modified version of the Software
23
+ or any work derived from it. Modifications for your own internal use are
24
+ allowed, but they remain subject to this license;
25
+ c) use the Software, or any part of it, to build, offer or support a
26
+ framework, library, tool or service that competes with the Software;
27
+ d) sell, sublicense, rent or host the Software itself as a product or service
28
+ for third parties, as opposed to hosting your own application built with
29
+ it;
30
+ e) remove or alter copyright, license or attribution notices;
31
+ f) use the name "ress.js" or the Licensor's names or marks to endorse or
32
+ promote your products without written permission.
33
+
34
+ 3. SCAFFOLDING OUTPUT
35
+ Files that @ressjs/create-ress-app copies into your project (templates and
36
+ generated configuration) are yours: you may use, modify and distribute them
37
+ without restriction. This does not extend to the Software packages that the
38
+ generated project installs as dependencies.
39
+
40
+ 4. SUPPORT
41
+ The Software is provided without any obligation of support, maintenance or
42
+ updates. The Licensor may offer support, maintenance, training or consulting
43
+ under a separate paid agreement; that agreement does not change this license
44
+ unless it says so explicitly and is signed by the Licensor.
45
+
46
+ 5. OWNERSHIP
47
+ The Software is licensed, not sold. The Licensor retains all rights not
48
+ expressly granted here. Feedback and suggestions you send may be used by the
49
+ Licensor without obligation to you.
50
+
51
+ 6. TERMINATION
52
+ This license ends automatically if you breach it. On termination you must
53
+ stop using the Software and delete your copies. Sections 4 to 8 survive
54
+ termination.
55
+
56
+ 7. NO WARRANTY
57
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58
+ IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
59
+ PARTICULAR PURPOSE AND NON-INFRINGEMENT.
60
+
61
+ 8. LIMITATION OF LIABILITY
62
+ TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE LICENSOR WILL NOT BE LIABLE FOR
63
+ ANY INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES, OR FOR LOSS OF
64
+ PROFITS, DATA OR BUSINESS, ARISING FROM THE USE OF OR INABILITY TO USE THE
65
+ SOFTWARE. THE LICENSOR'S TOTAL LIABILITY IS LIMITED TO THE AMOUNT YOU PAID
66
+ FOR THE SOFTWARE, WHICH MAY BE ZERO.
67
+
68
+ For other uses, including exceptions to section 2, contact the Licensor to
69
+ agree a separate license.
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @ressjs/vite-router
2
2
 
3
- Advanced Express router with **dynamic routes**, platform detection, and Server-Side Rendering (SSR) for RESS.js applications.
3
+ Express router for ress.js applications: file-based pages, dynamic routes and server-side rendering on top of Vite.
4
+
5
+ > Pre-release (`0.6.0-rc`). The API may still change before `0.6.0`.
4
6
 
5
7
  ## Installation
6
8
 
@@ -8,524 +10,16 @@ Advanced Express router with **dynamic routes**, platform detection, and Server-
8
10
  npm install @ressjs/vite-router
9
11
  ```
10
12
 
11
- ## Features
12
-
13
- - **🎯 Dynamic Routes**: Next.js-style routing with `[param]` syntax
14
- - **🎨 Platform Detection**: Automatic device, OS, and WebView detection
15
- - **⚡ SSR Support**: Complete server-side rendering with proper hydration
16
- - **📱 Smart Assets**: Platform-specific CSS/JS bundle resolution
17
- - **🔧 Middleware System**: File-based middleware with execution order control
18
- - **🔄 Development Mode**: Hot reload with fast refresh and dev server
19
- - **🚀 Production Ready**: Optimized builds with manifest-based asset loading
20
- - **📝 TypeScript**: Full TypeScript support with comprehensive type definitions
21
-
22
- ## Quick Start
23
-
24
- ### Vite Configuration
25
-
26
- Create a `vite.config.ts` file in your project root:
27
-
28
- ```typescript
29
- import { defineConfig } from 'vite'
30
- import react from '@vitejs/plugin-react'
31
- import { getClientEntriesInput, getViteSSRInput } from '@ressjs/vite-router'
32
-
33
- const isSSR = !!process.env.VITE_SSR_BUILD
34
-
35
- export default defineConfig(async () => ({
36
- plugins: [react()],
37
- server: {
38
- watch: {
39
- ignored: ['**/dist/.entries/**'] // Ignore generated entries
40
- }
41
- },
42
- build: {
43
- manifest: true,
44
- outDir: isSSR ? 'dist/server' : 'dist/client',
45
- rollupOptions: {
46
- input: isSSR
47
- ? getViteSSRInput() // SSR entry point
48
- : await getClientEntriesInput(), // Auto-generated client entries
49
- },
50
- ssr: isSSR,
51
- },
52
- }))
53
- ```
54
-
55
- **Important**: The router automatically generates entry files for each page/platform combination in `dist/.entries/`. These are used by Vite for building client bundles.
56
-
57
- ### Basic Setup
58
-
59
- ```typescript
60
- import express from 'express'
61
- import { createViteRouter } from '@ressjs/vite-router'
62
-
63
- const app = express()
64
- const router = createViteRouter({
65
- enablePlatformDetection: true,
66
- isProduction: process.env.NODE_ENV === 'production'
67
- })
68
-
69
- app.use('/', router)
70
- app.listen(3000, () => console.log('Server running on port 3000'))
71
- ```
72
-
73
- ### Development Server Setup
74
-
75
- Create a `server.js` file for development:
76
-
77
- ```typescript
78
- import { createServer } from 'vite'
79
- import { createViteRouter } from '@ressjs/vite-router'
80
- import express from 'express'
81
-
82
- async function createDevServer() {
83
- const app = express()
84
-
85
- // Create Vite server in middleware mode
86
- const vite = await createServer({
87
- server: { middlewareMode: true },
88
- appType: 'custom'
89
- })
90
-
91
- // Use vite's connect instance as middleware
92
- app.use(vite.ssrLoadModule)
93
-
94
- // Create router with Vite instance
95
- const router = createViteRouter({
96
- vite,
97
- enablePlatformDetection: true,
98
- isProduction: false
99
- })
100
-
101
- app.use('/', router)
102
- app.listen(3000, () => console.log('Dev server running on port 3000'))
103
- }
104
-
105
- createDevServer()
106
- ```
107
-
108
- ### Package.json Scripts
109
-
110
- Add these scripts to your `package.json`:
111
-
112
- ```json
113
- {
114
- "scripts": {
115
- "dev": "node server.js",
116
- "build": "npm run build:client && npm run build:server",
117
- "build:client": "vite build",
118
- "build:server": "VITE_SSR_BUILD=true vite build",
119
- "preview": "NODE_ENV=production node server.js",
120
- "type-check": "tsc --noEmit"
121
- },
122
- "dependencies": {
123
- "@ressjs/vite-router": "^0.5.0",
124
- "express": "^4.18.0",
125
- "react": "^18.0.0",
126
- "react-dom": "^18.0.0",
127
- "vite": "^5.0.0"
128
- },
129
- "devDependencies": {
130
- "@types/express": "^4.17.0",
131
- "@types/react": "^18.0.0",
132
- "@types/react-dom": "^18.0.0",
133
- "@vitejs/plugin-react": "^4.0.0",
134
- "typescript": "^5.0.0"
135
- }
136
- }
137
- ```
138
-
139
- ### TypeScript Backend Integration
140
-
141
- For full-stack TypeScript projects with backend APIs, use this enhanced configuration:
142
-
143
- ```json
144
- {
145
- "name": "my-fullstack-app",
146
- "type": "module",
147
- "scripts": {
148
- "dev": "PORT=3000 vite-node server.ts",
149
- "build": "npm run build:client && npm run build:server",
150
- "build:client": "vite build --outDir dist/client",
151
- "build:server": "cross-env VITE_SSR_BUILD=1 vite build --ssr --outDir dist/server",
152
- "preview": "cross-env NODE_ENV=production PORT=3000 tsx server.ts",
153
- "start": "npm run build && npm run preview"
154
- },
155
- "dependencies": {
156
- "@ressjs/vite-router": "^0.5.0",
157
- "cross-env": "^7.0.3",
158
- "express": "^4.18.0",
159
- "react": "^18.0.0",
160
- "react-dom": "^18.0.0",
161
- "tsx": "^4.7.1",
162
- "typescript": "^5.0.0",
163
- "vite": "^5.0.0"
164
- },
165
- "devDependencies": {
166
- "@types/express": "^4.17.0",
167
- "@types/node": "^22.0.0",
168
- "@types/react": "^18.0.0",
169
- "@types/react-dom": "^18.0.0",
170
- "@vitejs/plugin-react": "^4.0.0",
171
- "vite-node": "^3.2.0"
172
- }
173
- }
174
- ```
175
-
176
- **Key differences for TypeScript backends**:
177
- - **`vite-node server.ts`**: Direct TypeScript execution in development
178
- - **`tsx server.ts`**: Fast TypeScript runner for production
179
- - **`type: "module"`**: Enable ES modules in Node.js
180
- - **`cross-env`**: Cross-platform environment variables
181
-
182
- **When to use this setup**:
183
- - Building APIs alongside your frontend
184
- - Need database connections, authentication, file uploads
185
- - Want full TypeScript integration across the stack
186
- - Require additional Express middleware and routes
187
-
188
- **Key Points**:
189
- - **`VITE_SSR_BUILD=true`**: Environment variable that tells Vite config to build for SSR
190
- - **Separate builds**: Client and server are built separately with different entry points
191
- - **Auto-generated entries**: `getClientEntriesInput()` discovers all page/platform combinations
192
-
193
- ### Auto Server (WIP)
194
-
195
- ```typescript
196
- import { createAutoViteServer } from '@ressjs/vite-router'
197
-
198
- // Automatically configures Vite dev server with SSR (Work In Progress)
199
- const { start } = await createAutoViteServer({
200
- port: 3000,
201
- enablePlatformDetection: true
202
- })
203
-
204
- start()
205
- ```
206
-
207
- ## 🎯 Dynamic Routes
208
-
209
- Create pages with parameters using Next.js-style bracket syntax:
210
-
211
- ### File Structure
212
- ```
213
- app/pages/
214
- ├── index.tsx # / route
215
- ├── about.tsx # /about route
216
- ├── users/
217
- │ ├── index.tsx # /users route
218
- │ └── [id].tsx # /users/:id route
219
- ├── products/
220
- │ ├── [category].tsx # /products/:category route
221
- │ └── [category]/
222
- │ └── [id].tsx # /products/:category/:id route
223
- └── blog/
224
- └── [...slug].tsx # /blog/* route (coming soon)
225
- ```
226
-
227
- ### Route Examples
228
-
229
- | File | Route | Express Route | URL Example |
230
- |------|-------|---------------|-------------|
231
- | `users/[id].tsx` | `/users/[id]` | `/users/:id` | `/users/123` |
232
- | `products/[category]/[id].tsx` | `/products/[category]/[id]` | `/products/:category/:id` | `/products/phones/iphone` |
233
- | `photocard/[photoId].tsx` | `/photocard/[photoId]` | `/photocard/:photoId` | `/photocard/abc123xyz` |
234
-
235
- ### Accessing Parameters
236
-
237
- ```typescript
238
- // app/pages/users/[id].tsx
239
- export default function UserPage({ id, user }) {
240
- return (
241
- <div>
242
- <h1>User {id}</h1>
243
- <p>Name: {user.name}</p>
244
- </div>
245
- )
246
- }
247
-
248
- export async function getServerSideProps(req, res) {
249
- const { id } = req.params // Access route parameters
250
-
251
- // Fetch user data
252
- const user = await fetchUser(id)
253
-
254
- return {
255
- props: { id, user }
256
- }
257
- }
258
- ```
259
-
260
- ### Dynamic Route Styles
261
-
262
- Dynamic routes support platform-specific styles:
263
-
264
- ```
265
- app/pages/products/[id].tsx # Product page component
266
- app/pages/products/[id].scss # Desktop styles
267
- app/pages/products/[id].mobile.scss # Mobile styles
268
- app/pages/products/[id].webview.scss # WebView styles
269
- ```
270
-
271
- ## 🔧 Middleware System
272
-
273
- **Important**: Dynamic routes `[param].tsx` do **NOT** support dedicated middleware files. Use page-level or directory-level middleware instead.
274
-
275
- ### Middleware Execution Order
276
-
277
- ```
278
- app/pages/
279
- ├── middlewares.ts # --> Executes 1st (global)
280
- ├── products/
281
- │ ├── middlewares.ts # --> Executes 2nd (directory-level)
282
- │ ├── index.tsx
283
- │ ├── index.middlewares.ts # --> Executes 3rd (page-specific)
284
- │ └── [id].tsx # --> No middleware support for dynamic routes
285
- ├── users/
286
- │ ├── [id].tsx # --> Uses directory and global middleware only
287
- │ └── middlewares.ts # --> Executes for all /users/* routes
288
- └── checkout/
289
- ├── middlewares.ts # --> Executes 2nd for /checkout/*
290
- ├── step1.tsx
291
- ├── step1.middlewares.ts # --> Executes 3rd for /checkout/step1
292
- ├── step2.tsx
293
- └── step2.middlewares.ts # --> Executes 3rd for /checkout/step2
294
- ```
295
-
296
- ### Middleware Types
297
-
298
- #### 1. Global Middleware
299
- ```typescript
300
- // app/pages/middlewares.ts --> Executes 1st for ALL routes
301
- export default function globalMiddleware(req, res, next) {
302
- console.log('Global middleware for:', req.url)
303
- req.startTime = Date.now()
304
- next()
305
- }
306
- ```
307
-
308
- #### 2. Directory Middleware
309
- ```typescript
310
- // app/pages/products/middlewares.ts --> Executes 2nd for /products/*
311
- export default function productsMiddleware(req, res, next) {
312
- console.log('Products middleware for:', req.url)
313
- req.section = 'products'
314
- next()
315
- }
316
- ```
317
-
318
- #### 3. Page-Specific Middleware
319
- ```typescript
320
- // app/pages/products/index.middlewares.ts --> Executes 3rd for /products only
321
- export default function productListMiddleware(req, res, next) {
322
- console.log('Product list middleware')
323
- req.page = 'product-list'
324
- next()
325
- }
326
- ```
327
-
328
- #### ❌ Not Supported for Dynamic Routes
329
- ```typescript
330
- // ❌ app/pages/products/[id].middlewares.ts - NOT supported
331
- // Dynamic routes cannot have dedicated middleware files
332
- ```
333
-
334
- ### Complete Execution Flow Example
335
-
336
- For URL `/products/123`:
337
-
338
- 1. **Global**: `app/pages/middlewares.ts` (if exists)
339
- 2. **Directory**: `app/pages/products/middlewares.ts` (if exists)
340
- 3. **Page**: Built-in `getServerSideProps` from `[id].tsx`
341
- 4. **Render**: Component render and HTML generation
342
-
343
- ## 📱 Platform Detection
344
-
345
- The router automatically detects and serves platform-specific assets:
346
-
347
- ### Detection Capabilities
13
+ ## Getting started
348
14
 
349
- - **Device Type**: `phone`, `tablet`, `desktop`
350
- - **Operating System**: `ios`, `android`, `windows`, `macos`, `linux`
351
- - **Environment**: `webview`, `web`, `native`
352
- - **Category**: `webview.android`, `webview.ios`, `mobile`, etc.
353
-
354
- ### Platform Headers (React Native)
355
-
356
- React Native clients should send these headers:
357
-
358
- ```javascript
359
- {
360
- 'x-ressjs-platform': 'webview', // Required
361
- 'x-ressjs-os': 'ios', // Required
362
- 'x-ressjs-device': 'phone', // Required
363
- 'x-ressjs-version': Platform.Version, // Optional
364
- 'x-ressjs-app-version': '1.0.0' // Optional
365
- }
366
- ```
367
-
368
- ### Asset Resolution Priority
369
-
370
- For a page like `app/pages/home/index.tsx`:
371
-
372
- 1. **Device + OS Specific**: `index.phone.ios.scss`
373
- 2. **Device Specific**: `index.phone.scss`
374
- 3. **Category Specific**: `index.mobile.scss`
375
- 4. **WebView Specific**: `index.webview.scss`
376
- 5. **Base Fallback**: `index.scss`
377
-
378
- ### Platform CSS Examples
379
-
380
- ```
381
- app/pages/home/
382
- ├── index.tsx # React component
383
- ├── index.scss # Desktop/base styles
384
- ├── index.mobile.scss # Phone + tablet
385
- ├── index.phone.scss # Phone only
386
- ├── index.tablet.scss # Tablet only
387
- ├── index.webview.scss # All WebView
388
- ├── index.webview.ios.scss # iOS WebView
389
- ├── index.webview.android.scss # Android WebView
390
- └── index.desktop.linux.scss # Linux desktop
391
- ```
392
-
393
- ## 🎨 getServerSideProps
394
-
395
- Every page can export a `getServerSideProps` function for server-side data fetching:
396
-
397
- ```typescript
398
- export async function getServerSideProps(req, res) {
399
- // Access route parameters (for dynamic routes)
400
- const { id, category } = req.params
401
-
402
- // Access query parameters
403
- const { search, filter } = req.query
404
-
405
- // Access request headers
406
- const userAgent = req.headers['user-agent']
407
-
408
- // Return props for the component
409
- return {
410
- props: {
411
- id,
412
- data: await fetchData(id),
413
- timestamp: new Date().toISOString()
414
- },
415
- // Optional: HTML modifications
416
- title: `Product ${id}`,
417
- html: {
418
- head: {
419
- title: `Custom Title`,
420
- extraTags: ['<meta name="description" content="...">']
421
- }
422
- }
423
- }
424
- }
425
- ```
426
-
427
- ## 🚀 API Reference
428
-
429
- ### createViteRouter(options)
430
-
431
- ```typescript
432
- interface ViteRouterOptions {
433
- enablePlatformDetection?: boolean // Enable platform detection (default: true)
434
- vite?: any // Vite dev server instance
435
- manifest?: any // Production manifest
436
- templateHtml?: string // HTML template
437
- isProduction?: boolean // Production mode
438
- renderFunction?: (options: { // Custom render function
439
- url: string
440
- platform: string
441
- req: any
442
- }) => Promise<string>
443
- }
444
- ```
445
-
446
- ### createAutoViteServer(options)
447
-
448
- ```typescript
449
- interface AutoViteServerOptions {
450
- port?: number // Server port (default: 5173)
451
- base?: string // Base path (default: '/')
452
- enablePlatformDetection?: boolean // Enable platform detection (default: true)
453
- }
454
- ```
455
-
456
- ### Utility Functions
457
-
458
- ```typescript
459
- import {
460
- getPages,
461
- listDetectedPages,
462
- convertRouteToExpress
463
- } from '@ressjs/vite-router'
464
-
465
- // Get all discovered pages with route info
466
- const pages = getPages()
467
- // [{ route: '/users/[id]', expressRoute: '/users/:id', file: '...', abs: '...' }]
468
-
469
- // Convert Next.js route to Express route
470
- const expressRoute = convertRouteToExpress('/users/[id]') // '/users/:id'
471
- ```
472
-
473
- ## 🔧 Production Build
474
-
475
- ### Build Process
15
+ The recommended way to start is to generate an app, which comes already configured:
476
16
 
477
17
  ```bash
478
- # 1. Build client assets
479
- vite build --outDir dist/client
480
-
481
- # 2. Build server bundle
482
- vite build --ssr --outDir dist/server
483
-
484
- # 3. Start production server
485
- NODE_ENV=production node server.js
486
- ```
487
-
488
- ### Example Production Server
489
-
490
- ```typescript
491
- import express from 'express'
492
- import { createViteRouter } from '@ressjs/vite-router'
493
-
494
- const app = express()
495
-
496
- // Serve static assets
497
- app.use('/assets', express.static('dist/client/assets'))
498
-
499
- // Create router with production settings
500
- const router = createViteRouter({
501
- isProduction: true,
502
- enablePlatformDetection: true
503
- })
504
-
505
- app.use('/', router)
506
- app.listen(3000)
18
+ npx @ressjs/create-ress-app my-app
507
19
  ```
508
20
 
509
- ## 🐛 Troubleshooting
510
-
511
- ### Dynamic Route Not Working
512
-
513
- 1. **Check file naming**: Use `[param].tsx`, not `{param}.tsx`
514
- 2. **Verify parameters**: Access via `req.params.param` in `getServerSideProps`
515
- 3. **Build order**: Run `npm run build` after adding new dynamic routes
516
-
517
- ### Middleware Not Executing
518
-
519
- 1. **File naming**: Use `middlewares.ts` (plural) or `page.middlewares.ts`
520
- 2. **Dynamic routes**: Don't create `[param].middlewares.ts` - not supported
521
- 3. **Export**: Use `export default function` format
522
-
523
- ### Platform Detection Issues
524
-
525
- 1. **Headers**: Ensure React Native sends required `x-ressjs-*` headers
526
- 2. **CSS files**: Create platform-specific CSS files if needed
527
- 3. **Case sensitivity**: Use lowercase for OS names (`ios`, `android`)
21
+ Use the `@ressjs/cli` commands (`ress dev`, `ress build`, `ress start`) to run it.
528
22
 
529
- ## 📄 License
23
+ ## License
530
24
 
531
- MIT
25
+ Proprietary. See [LICENSE](./LICENSE).
@@ -0,0 +1,2 @@
1
+ export { Head, Script, Style } from '@ressjs/assets/client';
2
+ export type { HeadProps, ScriptProps, StyleProps } from '@ressjs/assets/client';
@@ -0,0 +1 @@
1
+ export { Head, Script, Style } from '@ressjs/assets/client';
@@ -0,0 +1,2 @@
1
+ export { Head, Script, Style } from '@ressjs/assets/client';
2
+ export type { HeadProps, ScriptProps, StyleProps } from '@ressjs/assets/client';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Style = exports.Script = exports.Head = void 0;
4
+ // Compatibility alias. The implementation is owned by @ressjs/assets.
5
+ var client_1 = require("@ressjs/assets/client");
6
+ Object.defineProperty(exports, "Head", { enumerable: true, get: function () { return client_1.Head; } });
7
+ Object.defineProperty(exports, "Script", { enumerable: true, get: function () { return client_1.Script; } });
8
+ Object.defineProperty(exports, "Style", { enumerable: true, get: function () { return client_1.Style; } });
@@ -0,0 +1,44 @@
1
+ import type { TrailingSlashMode } from './types';
2
+ /**
3
+ * Prefijo de ruta y barra final.
4
+ *
5
+ * Las dos reglas describen la **misma URL escrita de distintas maneras**, así que
6
+ * se aplican antes que cualquier otra cosa del pipeline: a partir de ahí, el
7
+ * manifest de rutas, las redirecciones y las reescrituras ven una sola forma de
8
+ * cada petición y no tienen que contemplar variantes.
9
+ */
10
+ /**
11
+ * La forma canónica de una ruta según la política de barra final, o `undefined`
12
+ * si ya lo es.
13
+ *
14
+ * Devolver `undefined` en vez de la misma cadena es lo que permite a quien llama
15
+ * distinguir «hay que redirigir» de «no hay nada que hacer» sin comparar strings.
16
+ */
17
+ export declare function canonicalTrailingSlash(pathname: string, mode: TrailingSlashMode): string | undefined;
18
+ /**
19
+ * Quita el prefijo de ruta.
20
+ *
21
+ * Devuelve `undefined` cuando la URL no cae bajo el prefijo: eso no es una ruta
22
+ * que esta aplicación atienda, y responder algo sería atender el sitio entero por
23
+ * dos direcciones distintas.
24
+ */
25
+ export declare function stripBasePath(pathname: string, basePath: string): string | undefined;
26
+ /**
27
+ * Antepone el prefijo a una ruta de la aplicación.
28
+ *
29
+ * Se usa para todo lo que el framework emite hacia el navegador —enlaces,
30
+ * artefactos, destinos de redirección—: una URL generada sin prefijo apunta
31
+ * afuera de la aplicación.
32
+ */
33
+ export declare function withBasePath(pathname: string, basePath: string): string;
34
+ /**
35
+ * El prefijo con el que se sirven los artefactos.
36
+ *
37
+ * `assets.cdnPrefix` gana sobre el prefijo de ruta porque describe otro origen:
38
+ * cuando existe, los artefactos no salen de este servidor y el prefijo de ruta
39
+ * no les aplica.
40
+ */
41
+ export declare function assetPrefixFor(options: {
42
+ basePath: string;
43
+ cdnPrefix?: string;
44
+ }): string;