@seip/bluebird-js 0.0.1 → 0.1.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/.env_example +53 -53
- package/AGENTS.md +426 -403
- package/LICENSE +1 -1
- package/README.md +292 -285
- package/app/routes/api.js +50 -50
- package/app/routes/web.js +55 -53
- package/app/views/about.js +63 -0
- package/app/views/dashboard.js +147 -0
- package/app/views/index.js +80 -0
- package/app/views/layouts/main/view.js +81 -0
- package/app/views/legal/terms.html +19 -0
- package/app/views/login.js +80 -0
- package/core/app.d.ts +18 -18
- package/core/app.js +684 -644
- package/core/auth.d.ts +13 -13
- package/core/auth.js +326 -326
- package/core/cache.d.ts +17 -17
- package/core/cache.js +475 -475
- package/core/cli/doctor.js +287 -287
- package/core/cli/ecosystem.js +162 -162
- package/core/cli/init.js +779 -779
- package/core/cli/migrate.js +541 -541
- package/core/cli/model.js +66 -66
- package/core/cli/nginx.js +199 -199
- package/core/cli/route.js +120 -120
- package/core/cli/view.js +55 -36
- package/core/config.d.ts +3 -3
- package/core/config.js +111 -111
- package/core/csrf.d.ts +3 -3
- package/core/csrf.js +114 -114
- package/core/database.d.ts +15 -15
- package/core/database.js +636 -636
- package/core/debug.d.ts +3 -3
- package/core/debug.js +249 -249
- package/core/hash.d.ts +3 -3
- package/core/hash.js +194 -194
- package/core/html.d.ts +42 -0
- package/core/html.js +217 -0
- package/core/index.d.ts +1176 -1071
- package/core/logger.d.ts +3 -3
- package/core/logger.js +127 -124
- package/core/middleware.d.ts +3 -3
- package/core/middleware.js +28 -28
- package/core/model.d.ts +19 -19
- package/core/model.js +600 -600
- package/core/queue.d.ts +13 -13
- package/core/queue.js +172 -172
- package/core/ratelimit.d.ts +3 -3
- package/core/ratelimit.js +145 -145
- package/core/redis.d.ts +21 -21
- package/core/redis.js +230 -230
- package/core/render-cache.js +212 -0
- package/core/render.d.ts +3 -3
- package/core/render.js +199 -555
- package/core/router.d.ts +3 -3
- package/core/router.js +171 -171
- package/core/seo.d.ts +3 -3
- package/core/seo.js +106 -106
- package/core/swagger.d.ts +3 -3
- package/core/swagger.js +60 -60
- package/core/upload.d.ts +13 -13
- package/core/upload.js +102 -102
- package/core/util/colors.js +82 -82
- package/core/validate.d.ts +15 -15
- package/core/validate.js +364 -364
- package/core/view-loader.js +162 -0
- package/core/vite.d.ts +3 -3
- package/core/vite.js +145 -145
- package/core/ws.d.ts +13 -13
- package/core/ws.js +245 -245
- package/index.js +18 -18
- package/jsconfig.json +15 -15
- package/package.json +85 -86
- package/production.md +273 -273
- package/public/css/bluebird.min.css +1 -1
- package/public/js/bluebird-client.js +1780 -1662
- package/public/js/bluebird.min.js +1072 -1072
- package/app/views/about.html +0 -161
- package/app/views/dashboard.html +0 -140
- package/app/views/index.html +0 -150
- package/app/views/login.html +0 -144
package/LICENSE
CHANGED
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,285 +1,292 @@
|
|
|
1
|
-
# Bluebird.js Framework
|
|
2
|
-
|
|
3
|
-
**Performance-first Node.js API and web framework with native JavaScript ESM, built-in JWT auth, HTML rendering, BaseModel, schema validation, and multi-level caching.**
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@seip/bluebird-js)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
[](https://nodejs.org)
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Introduction
|
|
12
|
-
|
|
13
|
-
Bluebird.js (`@seip/bluebird-js`) is a high-performance web and API framework built on Express (Node.js 22.18+). It provides native modern JavaScript ESM execution, HTML template rendering, multi-driver caching (in-memory by default with filesystem and Redis support), AES-256-GCM encrypted JWT authentication, BaseModel schema definitions, CSRF protection, background queues, and PM2 production clustering into a cohesive developer experience.
|
|
14
|
-
|
|
15
|
-
### Key Highlights
|
|
16
|
-
|
|
17
|
-
- **Pure Modern JavaScript (ESM):** Zero build steps, zero transpilation, pure Node.js 22.18+ ESM.
|
|
18
|
-
- **Root Entrypoint (`index.js`):** Clean and intuitive architecture with the entry file directly at the root.
|
|
19
|
-
- **
|
|
20
|
-
- **Lightweight BaseModel:** Static facade providing readable schemas, CRUD shortcuts, smart relations, soft deletes, automatic query cache invalidation, and validation bridges.
|
|
21
|
-
- **Native SQLite & Desktop Mode (Electron/Tauri):** Uses Node's built-in `node:sqlite` driver with zero compilation overhead, plus first-class `desktop: true` mode (`app.runDesktop()`) for read-only `.asar` bundles.
|
|
22
|
-
- **Decoupled Caching:** High-speed in-memory LRU cache by default, persistent filesystem fallback, and modular Redis support via `core/redis.js`.
|
|
23
|
-
- **CSRF, Rate Limiting & Security:** Native HMAC-SHA256 signed CSRF protection, built-in Rate Limiter (`rateLimit` in `App` or `App.rateLimit()`), automatic `/sitemap.xml` & `/robots.txt` generation, and secure HTTP headers without external bloat.
|
|
24
|
-
- **Production Ready:** Built-in PM2 clustering CLI (`npx bluebird-js make:ecosystem`), optimized Nginx generator (`npx bluebird-js nginx:conf`), and native runner (`npm start`).
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
## Quick Start
|
|
29
|
-
|
|
30
|
-
### 1. Requirements
|
|
31
|
-
|
|
32
|
-
- Node.js 22.18.0 or higher
|
|
33
|
-
- npm 10+
|
|
34
|
-
|
|
35
|
-
### 2. Installation and Initialization
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npm install @seip/bluebird-js
|
|
39
|
-
npx bluebird-js
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
The interactive CLI configures:
|
|
43
|
-
- Project title and port settings
|
|
44
|
-
- Database engine: `sqlite` (default, native zero-configuration), `mysql`, `postgres`, or `none`
|
|
45
|
-
- Connection credentials and database paths
|
|
46
|
-
- Automatic generation of `index.js`, `.env`, `jsconfig.json`, `app/`, and `public/`
|
|
47
|
-
|
|
48
|
-
### 3. Development Server
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
npm run dev
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
The server starts with Node's native file watcher (`--watch`) and loads `.env` automatically via `--env-file=.env`.
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## Project Structure
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
project/
|
|
62
|
-
├── index.js # Main application entrypoint
|
|
63
|
-
├── app/
|
|
64
|
-
│ ├── models/ # BaseModel definitions
|
|
65
|
-
│ │ ├── user.js # User model schema & methods
|
|
66
|
-
│ │ └── post.js # Post model schema & relations
|
|
67
|
-
│ ├── routes/ # Application routes
|
|
68
|
-
│ │ ├── api.js # REST API routes
|
|
69
|
-
│ │ └── web.js # HTML page routes
|
|
70
|
-
│ ├── views/ #
|
|
71
|
-
│ │ ├── layouts/ # Shared page layouts (e.g. main.
|
|
72
|
-
│ │ ├──
|
|
73
|
-
│ │ ├──
|
|
74
|
-
│ │
|
|
75
|
-
│ └──
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
│ ├──
|
|
81
|
-
│
|
|
82
|
-
│ └──
|
|
83
|
-
|
|
84
|
-
├──
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
├──
|
|
88
|
-
├── .
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
import
|
|
101
|
-
import
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
static
|
|
133
|
-
static
|
|
134
|
-
static
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
import
|
|
151
|
-
import
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
import
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
routerWeb.get("/
|
|
185
|
-
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
npx bluebird-js
|
|
276
|
-
npx bluebird-js make:
|
|
277
|
-
npx bluebird-js
|
|
278
|
-
npx bluebird-js
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
1
|
+
# Bluebird.js Framework
|
|
2
|
+
|
|
3
|
+
**Performance-first Node.js API and web framework with native JavaScript ESM, built-in JWT auth, HTML rendering, BaseModel, schema validation, and multi-level caching.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@seip/bluebird-js)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Introduction
|
|
12
|
+
|
|
13
|
+
Bluebird.js (`@seip/bluebird-js`) is a high-performance web and API framework built on Express (Node.js 22.18+). It provides native modern JavaScript ESM execution, HTML template rendering, multi-driver caching (in-memory by default with filesystem and Redis support), AES-256-GCM encrypted JWT authentication, BaseModel schema definitions, CSRF protection, background queues, and PM2 production clustering into a cohesive developer experience.
|
|
14
|
+
|
|
15
|
+
### Key Highlights
|
|
16
|
+
|
|
17
|
+
- **Pure Modern JavaScript (ESM):** Zero build steps, zero transpilation, pure Node.js 22.18+ ESM.
|
|
18
|
+
- **Root Entrypoint (`index.js`):** Clean and intuitive architecture with the entry file directly at the root.
|
|
19
|
+
- **Pure JavaScript Views & View Transitions:** Modern zero-build SSR with tagged template literals (html\`...\`), automatic XSS escaping, shared layouts, simple inline vanilla scripts, View Transitions SPA navigation, and uninterrupted audio/video streaming (data-persist="true").
|
|
20
|
+
- **Lightweight BaseModel:** Static facade providing readable schemas, CRUD shortcuts, smart relations, soft deletes, automatic query cache invalidation, and validation bridges.
|
|
21
|
+
- **Native SQLite & Desktop Mode (Electron/Tauri):** Uses Node's built-in `node:sqlite` driver with zero compilation overhead, plus first-class `desktop: true` mode (`app.runDesktop()`) for read-only `.asar` bundles.
|
|
22
|
+
- **Decoupled Caching:** High-speed in-memory LRU cache by default, persistent filesystem fallback, and modular Redis support via `core/redis.js`.
|
|
23
|
+
- **CSRF, Rate Limiting & Security:** Native HMAC-SHA256 signed CSRF protection, built-in Rate Limiter (`rateLimit` in `App` or `App.rateLimit()`), automatic `/sitemap.xml` & `/robots.txt` generation, and secure HTTP headers without external bloat.
|
|
24
|
+
- **Production Ready:** Built-in PM2 clustering CLI (`npx bluebird-js make:ecosystem`), optimized Nginx generator (`npx bluebird-js nginx:conf`), and native runner (`npm start`).
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
### 1. Requirements
|
|
31
|
+
|
|
32
|
+
- Node.js 22.18.0 or higher
|
|
33
|
+
- npm 10+
|
|
34
|
+
|
|
35
|
+
### 2. Installation and Initialization
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install @seip/bluebird-js
|
|
39
|
+
npx bluebird-js
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The interactive CLI configures:
|
|
43
|
+
- Project title and port settings
|
|
44
|
+
- Database engine: `sqlite` (default, native zero-configuration), `mysql`, `postgres`, or `none`
|
|
45
|
+
- Connection credentials and database paths
|
|
46
|
+
- Automatic generation of `index.js`, `.env`, `jsconfig.json`, `app/`, and `public/`
|
|
47
|
+
|
|
48
|
+
### 3. Development Server
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm run dev
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The server starts with Node's native file watcher (`--watch`) and loads `.env` automatically via `--env-file=.env`.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Project Structure
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
project/
|
|
62
|
+
├── index.js # Main application entrypoint
|
|
63
|
+
├── app/
|
|
64
|
+
│ ├── models/ # BaseModel definitions
|
|
65
|
+
│ │ ├── user.js # User model schema & methods
|
|
66
|
+
│ │ └── post.js # Post model schema & relations
|
|
67
|
+
│ ├── routes/ # Application routes
|
|
68
|
+
│ │ ├── api.js # REST API routes
|
|
69
|
+
│ │ └── web.js # HTML page routes
|
|
70
|
+
│ ├── views/ # Pure JavaScript ESM views
|
|
71
|
+
│ │ ├── layouts/ # Shared page layouts (e.g. main/view.js)
|
|
72
|
+
│ │ ├── index.js # Public home view
|
|
73
|
+
│ │ ├── about.js # About page view
|
|
74
|
+
│ │ ├── login.js # Sign-in page view
|
|
75
|
+
│ │ └── dashboard.js # Protected dashboard view
|
|
76
|
+
│ └── jobs/ # Background worker job handlers
|
|
77
|
+
├── src/ # Frontend source (React Islands)
|
|
78
|
+
│ └── islands/ # Interactive React island components
|
|
79
|
+
├── public/ # Public static assets (CSS, JS, images, fonts)
|
|
80
|
+
│ ├── css/
|
|
81
|
+
│ ├── js/
|
|
82
|
+
│ │ └── bluebird-client.js # View Transitions, partial swaps & islands runtime
|
|
83
|
+
│ └── dist/ # Production Vite hashed bundles
|
|
84
|
+
├── core/ # Bluebird.js framework core
|
|
85
|
+
├── database/ # SQLite storage and SQL migrations
|
|
86
|
+
│ └── migrations/
|
|
87
|
+
├── ecosystem.config.cjs # PM2 cluster configuration (production)
|
|
88
|
+
├── production.md # Production deployment guide
|
|
89
|
+
├── .env # Environment variables
|
|
90
|
+
└── package.json
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Usage Examples
|
|
96
|
+
|
|
97
|
+
### 1. Application Entrypoint (`index.js`)
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
import App from "@seip/bluebird-js/core/app.js";
|
|
101
|
+
import routerApi from "./app/routes/api.js";
|
|
102
|
+
import routerWeb from "./app/routes/web.js";
|
|
103
|
+
|
|
104
|
+
const app = new App({
|
|
105
|
+
routes: [routerWeb, routerApi],
|
|
106
|
+
port: process.env.PORT || 3000,
|
|
107
|
+
rateLimit: { max: 120, windowMs: 60000 },
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
app.run();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
For **Electron / Desktop** applications:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
const app = new App({
|
|
117
|
+
desktop: true,
|
|
118
|
+
userDataPath: electronApp.getPath("userData"),
|
|
119
|
+
routes: [routerWeb, routerApi],
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const { url } = await app.runDesktop();
|
|
123
|
+
mainWindow.loadURL(url);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 2. Defining a Model (`app/models/user.js`)
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
import Model from "@seip/bluebird-js/core/model.js";
|
|
130
|
+
|
|
131
|
+
export default class User extends Model {
|
|
132
|
+
static table = "users";
|
|
133
|
+
static primaryKey = "id";
|
|
134
|
+
static timestamps = true;
|
|
135
|
+
static softDelete = true;
|
|
136
|
+
|
|
137
|
+
static schema = {
|
|
138
|
+
id: { type: "int", primary: true, auto: true },
|
|
139
|
+
name: { type: "string", length: 150, required: true },
|
|
140
|
+
email: { type: "string", length: 150, unique: true, required: true, email: true },
|
|
141
|
+
password: { type: "string", length: 255, required: true, min: 8, hidden: true, hash: true },
|
|
142
|
+
role: { type: "string", length: 20, default: "user", in: ["user", "admin"] },
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 3. REST API Routes (`app/routes/api.js`)
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
import App from "@seip/bluebird-js/core/app.js";
|
|
151
|
+
import Router from "@seip/bluebird-js/core/router.js";
|
|
152
|
+
import User from "../models/user.js";
|
|
153
|
+
|
|
154
|
+
const routerApi = new Router("/api");
|
|
155
|
+
|
|
156
|
+
routerApi.get("/users", async (req, res) => {
|
|
157
|
+
const users = await User.all({ limit: 50, order: "id DESC" });
|
|
158
|
+
res.ok({ users });
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
routerApi.post(
|
|
162
|
+
"/users",
|
|
163
|
+
App.rateLimit({ max: 10, windowMs: 60000 }),
|
|
164
|
+
User.validator("create").middleware(),
|
|
165
|
+
async (req, res) => {
|
|
166
|
+
const userId = await User.create(req.body);
|
|
167
|
+
res.created({ id: userId }, "User created successfully");
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
export default routerApi;
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### 4. HTML Views, Layouts & Server Partials (`app/routes/web.js`)
|
|
175
|
+
|
|
176
|
+
When `{ seo: true }` is enabled on a router, Bluebird automatically generates `/sitemap.xml` and `/robots.txt`:
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
import Router from "@seip/bluebird-js/core/router.js";
|
|
180
|
+
import Render from "@seip/bluebird-js/core/render.js";
|
|
181
|
+
|
|
182
|
+
const routerWeb = new Router("/", { seo: true });
|
|
183
|
+
|
|
184
|
+
routerWeb.get("/", Render.view("index", { title: "Bluebird Application" }));
|
|
185
|
+
routerWeb.get("/stats-card", (req, res) => {
|
|
186
|
+
return Render.partial(res, "stat_card", { label: "Revenue", val: "$12,400", active: true });
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
export default routerWeb;
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Inside your views (`app/views/dashboard.js`), use pure JavaScript functions with `html` tagged templates and plain vanilla `<script>` tags:
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
// app/views/dashboard.js
|
|
196
|
+
import { html } from "@seip/bluebird-js/core/html.js";
|
|
197
|
+
|
|
198
|
+
export const layout = "main";
|
|
199
|
+
export const head = (data) => ({ title: `Dashboard — ${data.user?.name || "Member"}` });
|
|
200
|
+
|
|
201
|
+
export default function DashboardView({ user, metrics }) {
|
|
202
|
+
const initial = metrics?.unread || 0;
|
|
203
|
+
|
|
204
|
+
return html`
|
|
205
|
+
<section class="dashboard-grid">
|
|
206
|
+
<h1>Welcome back, ${user.name}</h1>
|
|
207
|
+
|
|
208
|
+
<div class="card">
|
|
209
|
+
<button id="btnDec" class="btn-sm">-</button>
|
|
210
|
+
<span id="counter" class="font-bold">${initial}</span>
|
|
211
|
+
<button id="btnInc" class="btn-sm">+</button>
|
|
212
|
+
</div>
|
|
213
|
+
</section>
|
|
214
|
+
|
|
215
|
+
<!-- Native inline script: clean, readable, zero build steps -->
|
|
216
|
+
<script>
|
|
217
|
+
(() => {
|
|
218
|
+
let count = ${initial};
|
|
219
|
+
const el = document.getElementById("counter");
|
|
220
|
+
document.getElementById("btnInc")?.addEventListener("click", () => {
|
|
221
|
+
count++;
|
|
222
|
+
if (el) el.textContent = count;
|
|
223
|
+
});
|
|
224
|
+
document.getElementById("btnDec")?.addEventListener("click", () => {
|
|
225
|
+
if (count > 0) count--;
|
|
226
|
+
if (el) el.textContent = count;
|
|
227
|
+
});
|
|
228
|
+
})();
|
|
229
|
+
</script>
|
|
230
|
+
`;
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
> **Live Reload:** When running development (`npm run dev` with `node --watch`), Bluebird automatically reloads the browser tab via native Server-Sent Events whenever changes trigger a server restart. No plugins or browser extensions needed.
|
|
235
|
+
|
|
236
|
+
> **Architecture Tip:** Keep business operations, third-party APIs, and database transactions in `app/services/` or `app/models/`. Views should remain declarative, lightweight, and focused on presentation.
|
|
237
|
+
|
|
238
|
+
### 5. Multi-Driver Caching (`core/cache.js`)
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
import Cache from "@seip/bluebird-js/core/cache.js";
|
|
242
|
+
|
|
243
|
+
await Cache.set("metrics", { activeUsers: 450 }, 60, { driver: "memory" });
|
|
244
|
+
const metrics = await Cache.get("metrics", { driver: "memory" });
|
|
245
|
+
|
|
246
|
+
await Cache.set("report", htmlContent, 300, { driver: "file" });
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### 6. Raw Static HTML Delivery (`Render.html`)
|
|
250
|
+
|
|
251
|
+
For static legal documents, terms of service, or offline pages without server-side templating overhead:
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
routerWeb.get("/terms", (req, res) => Render.html(res, "legal/terms.html", { ttl: 86400 }));
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Production Deployment
|
|
260
|
+
|
|
261
|
+
Bluebird.js supports direct Node.js execution and PM2 process clustering out of the box:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
npm start # Starts via Node.js
|
|
265
|
+
npx bluebird-js make:ecosystem --start # Generates ecosystem config and launches via PM2
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
For complete instructions covering PM2, systemd services, Nginx reverse proxy setup, and optional standalone Docker configurations, read the [Production Guide](production.md).
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Developer Tooling CLI
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
npx bluebird-js doctor # Diagnostic audit and HTTP smoke tests
|
|
276
|
+
npx bluebird-js make:model <Name> # Generates BaseModel class
|
|
277
|
+
npx bluebird-js make:route <name> [--auth] # Scaffolds REST route
|
|
278
|
+
npx bluebird-js make:view <name> [--ejs] # Scaffolds HTML/EJS template
|
|
279
|
+
npx bluebird-js make:migration <name> [--model <M>] # Generates database migration
|
|
280
|
+
npx bluebird-js migrate # Executes pending migrations
|
|
281
|
+
npx bluebird-js seed # Executes database seeds
|
|
282
|
+
npx bluebird-js nginx:conf [domain] [port] [root] # Generates Nginx reverse proxy configuration
|
|
283
|
+
npx bluebird-js make:ecosystem [--start] # Generates PM2 clustering config
|
|
284
|
+
npx bluebird-js add react-islands # Scaffolds React Islands, Vite & Client Router
|
|
285
|
+
npx bluebird-js add <module> # Installs optional on-demand package
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
MIT License. Copyright (c) 2026 Seip25.
|