mastercontroller 1.3.8 → 1.3.10
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/.claude/settings.local.json +4 -1
- package/FIXES_APPLIED.md +378 -0
- package/MasterAction.js +10 -263
- package/MasterControl.js +128 -27
- package/MasterRequest.js +6 -0
- package/MasterRouter.js +27 -32
- package/PERFORMANCE_SECURITY_AUDIT.md +677 -0
- package/README.md +117 -43
- package/monitoring/README.md +3112 -0
- package/package.json +1 -1
- package/security/README.md +1805 -0
- package/test-raw-body-preservation.js +128 -0
- package/MasterCors.js.tmp +0 -0
- package/MasterHtml.js +0 -649
- package/MasterPipeline.js.tmp +0 -0
- package/MasterRequest.js.tmp +0 -0
- package/MasterRouter.js.tmp +0 -0
- package/MasterSocket.js.tmp +0 -0
- package/MasterTemp.js.tmp +0 -0
- package/MasterTemplate.js +0 -230
- package/MasterTimeout.js.tmp +0 -0
- package/TemplateOverwrite.js +0 -41
- package/TemplateOverwrite.js.tmp +0 -0
- package/ssr/hydration-client.js +0 -93
- package/ssr/runtime-ssr.cjs +0 -553
- package/ssr/ssr-shims.js +0 -73
package/README.md
CHANGED
|
@@ -444,6 +444,60 @@ class UsersController {
|
|
|
444
444
|
|
|
445
445
|
## Views and Templates
|
|
446
446
|
|
|
447
|
+
MasterController v1.3+ uses a **pluggable view architecture**, allowing you to choose any template engine (MasterView, EJS, Pug, React SSR, etc.) or build your own adapter.
|
|
448
|
+
|
|
449
|
+
### Quick Start with MasterView
|
|
450
|
+
|
|
451
|
+
MasterView is the official view engine with built-in SSR support:
|
|
452
|
+
|
|
453
|
+
```bash
|
|
454
|
+
npm install masterview
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
```javascript
|
|
458
|
+
// config/initializers/config.js
|
|
459
|
+
const master = require('mastercontroller');
|
|
460
|
+
const MasterView = require('masterview');
|
|
461
|
+
|
|
462
|
+
// Register view engine
|
|
463
|
+
master.useView(MasterView, {
|
|
464
|
+
ssr: true, // Enable server-side rendering
|
|
465
|
+
layoutPath: 'app/views/layouts/master.html'
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
// Rest of your config...
|
|
469
|
+
master.startMVC('config');
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
### Controller Usage (Same for All View Engines)
|
|
473
|
+
|
|
474
|
+
```javascript
|
|
475
|
+
class HomeController {
|
|
476
|
+
index(obj) {
|
|
477
|
+
// Render view with layout
|
|
478
|
+
this.returnView({
|
|
479
|
+
title: 'Home',
|
|
480
|
+
message: 'Welcome!'
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
partial(obj) {
|
|
485
|
+
// Render partial (no layout)
|
|
486
|
+
this.returnPartialView('shared/header', { user: 'John' });
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
raw(obj) {
|
|
490
|
+
// Render raw HTML file
|
|
491
|
+
this.returnViewWithoutEngine('static/page.html');
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
api(obj) {
|
|
495
|
+
// Return JSON (works with any view engine)
|
|
496
|
+
this.returnJson({ status: 'ok', data: [] });
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
```
|
|
500
|
+
|
|
447
501
|
### View Structure
|
|
448
502
|
|
|
449
503
|
```
|
|
@@ -451,50 +505,81 @@ app/
|
|
|
451
505
|
views/
|
|
452
506
|
layouts/
|
|
453
507
|
master.html # Main layout
|
|
508
|
+
home/
|
|
509
|
+
index.html # Home index view
|
|
510
|
+
about.html # Home about view
|
|
454
511
|
users/
|
|
455
512
|
index.html # Users index view
|
|
456
513
|
show.html # Users show view
|
|
457
514
|
```
|
|
458
515
|
|
|
459
|
-
###
|
|
516
|
+
### Alternative View Engines
|
|
460
517
|
|
|
461
|
-
|
|
462
|
-
<!DOCTYPE html>
|
|
463
|
-
<html>
|
|
464
|
-
<head>
|
|
465
|
-
<title>{{title}}</title>
|
|
466
|
-
</head>
|
|
467
|
-
<body>
|
|
468
|
-
<header>
|
|
469
|
-
<h1>My App</h1>
|
|
470
|
-
</header>
|
|
518
|
+
#### Using EJS
|
|
471
519
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
520
|
+
```bash
|
|
521
|
+
npm install ejs
|
|
522
|
+
```
|
|
475
523
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
524
|
+
```javascript
|
|
525
|
+
const EJSView = {
|
|
526
|
+
register(master) {
|
|
527
|
+
master.controllerList.returnView = async function(data, location) {
|
|
528
|
+
const html = await ejs.renderFile(viewPath, data);
|
|
529
|
+
this.__response.end(html);
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
master.useView(EJSView);
|
|
481
535
|
```
|
|
482
536
|
|
|
483
|
-
|
|
537
|
+
See [MasterView Examples](https://github.com/yourorg/masterview/tree/master/examples) for EJS, Pug, and React SSR adapters.
|
|
484
538
|
|
|
485
|
-
|
|
486
|
-
|
|
539
|
+
#### Using Pug
|
|
540
|
+
|
|
541
|
+
```bash
|
|
542
|
+
npm install pug
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
```javascript
|
|
546
|
+
const PugView = {
|
|
547
|
+
register(master) {
|
|
548
|
+
master.controllerList.returnView = function(data, location) {
|
|
549
|
+
const html = pug.renderFile(viewPath, data);
|
|
550
|
+
this.__response.end(html);
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
master.useView(PugView);
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
#### Using React SSR
|
|
559
|
+
|
|
560
|
+
```bash
|
|
561
|
+
npm install react react-dom
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
```javascript
|
|
565
|
+
const ReactSSRView = {
|
|
566
|
+
register(master) {
|
|
567
|
+
master.controllerList.returnView = function(data, location) {
|
|
568
|
+
const Component = require(componentPath);
|
|
569
|
+
const html = ReactDOMServer.renderToString(
|
|
570
|
+
React.createElement(Component, data)
|
|
571
|
+
);
|
|
572
|
+
this.__response.end(wrapInHTML(html, data));
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
};
|
|
487
576
|
|
|
488
|
-
|
|
489
|
-
{{#each users}}
|
|
490
|
-
<li>{{this}}</li>
|
|
491
|
-
{{/each}}
|
|
492
|
-
</ul>
|
|
577
|
+
master.useView(ReactSSRView);
|
|
493
578
|
```
|
|
494
579
|
|
|
495
|
-
### Template Syntax
|
|
580
|
+
### MasterView Template Syntax
|
|
496
581
|
|
|
497
|
-
|
|
582
|
+
MasterView uses `{{...}}` syntax similar to Handlebars:
|
|
498
583
|
|
|
499
584
|
```html
|
|
500
585
|
<!-- Variables -->
|
|
@@ -504,22 +589,11 @@ MasterController uses Handlebars-style templates:
|
|
|
504
589
|
<!-- HTML escaping (automatic) -->
|
|
505
590
|
{{description}}
|
|
506
591
|
|
|
507
|
-
<!--
|
|
508
|
-
{{
|
|
509
|
-
<a href="/admin">Admin Panel</a>
|
|
510
|
-
{{/if}}
|
|
511
|
-
|
|
512
|
-
{{#unless isGuest}}
|
|
513
|
-
<p>Welcome back!</p>
|
|
514
|
-
{{/unless}}
|
|
515
|
-
|
|
516
|
-
<!-- Loops -->
|
|
517
|
-
{{#each items}}
|
|
518
|
-
<div>{{this.name}}</div>
|
|
519
|
-
{{/each}}
|
|
592
|
+
<!-- Raw HTML (use sparingly, XSS risk) -->
|
|
593
|
+
{{{htmlContent}}}
|
|
520
594
|
|
|
521
595
|
<!-- Partials -->
|
|
522
|
-
{{
|
|
596
|
+
{{html.renderPartial('shared/header', {user: currentUser})}}
|
|
523
597
|
```
|
|
524
598
|
|
|
525
599
|
---
|