mastercontroller 1.2.8 → 1.2.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/MasterAction.js +1 -13
- package/MasterRouter.js +1 -1
- package/README.md +44 -0
- package/package.json +1 -1
package/MasterAction.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
// version 0.0.
|
|
2
|
+
// version 0.0.22
|
|
3
3
|
|
|
4
4
|
var master = require('./MasterControl');
|
|
5
5
|
var fileserver = require('fs');
|
|
@@ -133,18 +133,6 @@ class MasterAction{
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
returnReact(data, location){
|
|
137
|
-
|
|
138
|
-
var masterView = null;
|
|
139
|
-
data = data === undefined ? {} : data;
|
|
140
|
-
this.params = this.params === undefined ? {} : this.params;
|
|
141
|
-
this.params = tools.combineObjects(data, this.params);
|
|
142
|
-
var func = master.viewList;
|
|
143
|
-
this.params = tools.combineObjects(this.params, func);
|
|
144
|
-
var html = master.reactView.compile(this.__currentRoute.toController, this.__currentRoute.toAction, this.__currentRoute.root);
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
136
|
returnView(data, location){
|
|
149
137
|
|
|
150
138
|
var masterView = null;
|
package/MasterRouter.js
CHANGED
package/README.md
CHANGED
|
@@ -49,6 +49,50 @@ Use `setupServer('https', credentials)` or configure via environment TLS; see do
|
|
|
49
49
|
- `docs/server-setup-nginx-reverse-proxy.md`
|
|
50
50
|
- `docs/environment-tls-reference.md`
|
|
51
51
|
|
|
52
|
+
### How File Uploads Work
|
|
53
|
+
|
|
54
|
+
MasterController handles file uploads through the `formidable` library (v3.5.4+) integrated into the request parsing pipeline in `MasterRequest.js`.
|
|
55
|
+
|
|
56
|
+
**Processing Flow:**
|
|
57
|
+
|
|
58
|
+
1. **Content-Type Detection** - When a request arrives, the framework parses the `Content-Type` header to determine how to handle the request body (`MasterRequest.js:34-36`)
|
|
59
|
+
|
|
60
|
+
2. **Multipart Form Data** - For `multipart/form-data` requests (file uploads), the framework uses formidable's `IncomingForm` to parse the request (`MasterRequest.js:43-78`)
|
|
61
|
+
|
|
62
|
+
3. **Event-Based Parsing** - Formidable emits events during parsing:
|
|
63
|
+
- `field` event: Captures regular form fields and adds them to `parsedURL.formData.fields`
|
|
64
|
+
- `file` event: Captures uploaded files and stores them in `parsedURL.formData.files` as arrays (supporting multiple file uploads per field)
|
|
65
|
+
- `end` event: Signals completion and resolves the promise with parsed data
|
|
66
|
+
|
|
67
|
+
4. **File Metadata** - Each uploaded file object includes:
|
|
68
|
+
- `name` or `originalFilename`: The original filename
|
|
69
|
+
- `extension`: Extracted file extension (e.g., `.jpg`, `.pdf`)
|
|
70
|
+
- `filepath`: Temporary location where formidable stored the file
|
|
71
|
+
- Other formidable metadata (size, mimetype, etc.)
|
|
72
|
+
|
|
73
|
+
5. **Accessing Uploads in Controllers** - In your controller actions, access uploaded files via:
|
|
74
|
+
```js
|
|
75
|
+
this.params.formData.files['fieldName'][0] // First file for 'fieldName'
|
|
76
|
+
this.params.formData.fields['textField'] // Regular form fields
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
6. **Multiple Files** - Files are always stored as arrays in `parsedURL.formData.files[field]`, allowing multiple files to be uploaded with the same field name (`MasterRequest.js:59-65`)
|
|
80
|
+
|
|
81
|
+
7. **Cleanup** - Use `this.request.deleteFileBuffer(filePath)` to remove temporary files after processing (`MasterRequest.js:162-169`)
|
|
82
|
+
|
|
83
|
+
**Configuration Options:**
|
|
84
|
+
|
|
85
|
+
You can configure file upload behavior via `master.request.init()`:
|
|
86
|
+
- `disableFormidableMultipartFormData`: Set to `true` to skip file upload parsing
|
|
87
|
+
- `formidable`: Pass options directly to formidable (upload directory, max file size, etc.)
|
|
88
|
+
|
|
89
|
+
**Supported Content Types:**
|
|
90
|
+
- `multipart/form-data` - File uploads
|
|
91
|
+
- `application/x-www-form-urlencoded` - Standard forms
|
|
92
|
+
- `application/json` - JSON payloads
|
|
93
|
+
- `text/plain` - Plain text (1MB limit)
|
|
94
|
+
- `text/html` - HTML content
|
|
95
|
+
|
|
52
96
|
### Production tips
|
|
53
97
|
- Prefer a reverse proxy for TLS and serve Node on a high port.
|
|
54
98
|
- If keeping TLS in Node, harden TLS and manage cert rotation.
|
package/package.json
CHANGED