ultimate-express 1.3.6 → 1.3.8
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/package.json +1 -1
- package/src/declarative.js +15 -0
- package/src/middlewares.js +1 -4
package/package.json
CHANGED
package/src/declarative.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const acorn = require("acorn");
|
|
2
|
+
const { stringify } = require("./utils.js");
|
|
2
3
|
const uWS = require("uWebSockets.js");
|
|
3
4
|
|
|
4
5
|
const parser = acorn.Parser;
|
|
@@ -272,6 +273,20 @@ module.exports = function compileDeclarative(cb, app) {
|
|
|
272
273
|
return false;
|
|
273
274
|
}
|
|
274
275
|
body.push(...stuff.reverse());
|
|
276
|
+
} else if(arg.type === 'ObjectExpression') {
|
|
277
|
+
// only simple objects can be optimized
|
|
278
|
+
for(let property of arg.properties) {
|
|
279
|
+
if(property.key.type !== 'Identifier' && property.key.type !== 'Literal') {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
if(property.value.type !== 'Literal') {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if(typeof app.get('json replacer') !== 'undefined' && typeof app.get('json replacer') !== 'string') {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
body.push({type: 'text', value: stringify(JSON.parse(code.slice(arg.start, arg.end)), app.get('json replacer'), app.get('json spaces'), app.get('json escape'))});
|
|
275
290
|
} else {
|
|
276
291
|
return false;
|
|
277
292
|
}
|
package/src/middlewares.js
CHANGED
|
@@ -144,11 +144,8 @@ function createBodyParser(defaultType, beforeReturn) {
|
|
|
144
144
|
if(typeof options.limit === 'undefined') options.limit = bytes('100kb');
|
|
145
145
|
else options.limit = bytes(options.limit);
|
|
146
146
|
|
|
147
|
-
if(typeof options.type === 'undefined') options.type = defaultType;
|
|
148
|
-
else if(typeof options.type !== 'string') {
|
|
149
|
-
throw new Error('type must be a string');
|
|
150
|
-
}
|
|
151
147
|
if(typeof options.inflate === 'undefined') options.inflate = true;
|
|
148
|
+
if(typeof options.type === 'undefined') options.type = defaultType;
|
|
152
149
|
if(typeof options.type === 'string') {
|
|
153
150
|
if(!options.type.includes("*")) {
|
|
154
151
|
options.simpleType = options.type;
|