@innet/server 1.6.0 → 1.6.2
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innet/server",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "Create server-side application with innet",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.es6.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/d8corp/innet-server",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@cantinc/utils": "^1.2.
|
|
25
|
+
"@cantinc/utils": "^1.2.7",
|
|
26
26
|
"@innet/html": "^1.0.1",
|
|
27
27
|
"@innet/jsx": "^1.1.0",
|
|
28
28
|
"@innet/switch": "^1.0.0",
|
|
@@ -15,11 +15,14 @@ function getStatus(status) {
|
|
|
15
15
|
return status;
|
|
16
16
|
return redirectStatuses[status] || 301;
|
|
17
17
|
}
|
|
18
|
+
function customEncode(url) {
|
|
19
|
+
return encodeURI(url.replaceAll('%20', ' '));
|
|
20
|
+
}
|
|
18
21
|
function redirect({ props, children }, handler) {
|
|
19
22
|
const { res } = handler[ACTION];
|
|
20
23
|
const { to, status = 301, encode } = props;
|
|
21
24
|
res.writeHead(getStatus(status), {
|
|
22
|
-
location: encode ?
|
|
25
|
+
location: encode ? customEncode(to) : to,
|
|
23
26
|
});
|
|
24
27
|
return null;
|
|
25
28
|
}
|
|
@@ -19,12 +19,15 @@ function getStatus(status) {
|
|
|
19
19
|
return status;
|
|
20
20
|
return redirectStatuses[status] || 301;
|
|
21
21
|
}
|
|
22
|
+
function customEncode(url) {
|
|
23
|
+
return encodeURI(url.replaceAll('%20', ' '));
|
|
24
|
+
}
|
|
22
25
|
function redirect(_a, handler) {
|
|
23
26
|
var props = _a.props; _a.children;
|
|
24
27
|
var res = handler[Action.ACTION].res;
|
|
25
28
|
var to = props.to, _b = props.status, status = _b === void 0 ? 301 : _b, encode = props.encode;
|
|
26
29
|
res.writeHead(getStatus(status), {
|
|
27
|
-
location: encode ?
|
|
30
|
+
location: encode ? customEncode(to) : to,
|
|
28
31
|
});
|
|
29
32
|
return null;
|
|
30
33
|
}
|
|
@@ -13,4 +13,4 @@ export interface ValidationContext {
|
|
|
13
13
|
handleError?: (e: ValidationResponse<any>) => any;
|
|
14
14
|
}
|
|
15
15
|
export declare const validationContext: Context<ValidationContext, ValidationContext>;
|
|
16
|
-
export declare function validation<T extends object, E extends object>({ props, children }: ValidationJsxElement<T>, handler: any):
|
|
16
|
+
export declare function validation<T extends object, E extends object>({ props, children }: ValidationJsxElement<T>, handler: any): any;
|
|
@@ -14,13 +14,12 @@ function validation({ props, children }, handler) {
|
|
|
14
14
|
const data = action[resource];
|
|
15
15
|
if (!data)
|
|
16
16
|
throw Error(`cannot find ${resource} in action`);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
17
|
+
const result = validation$1(map, data);
|
|
18
|
+
if (result) {
|
|
19
|
+
const { handleError } = validationContext.get(handler);
|
|
20
|
+
return handleError ? innet(handleError(result), handler) : undefined;
|
|
21
|
+
}
|
|
22
|
+
return innet(children, handler);
|
|
24
23
|
};
|
|
25
24
|
if (resource === 'body' || resource === 'files') {
|
|
26
25
|
return action.parseBody().then(run);
|
|
@@ -23,13 +23,12 @@ function validation(_a, handler) {
|
|
|
23
23
|
var data = action[resource];
|
|
24
24
|
if (!data)
|
|
25
25
|
throw Error("cannot find ".concat(resource, " in action"));
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
26
|
+
var result = utils.validation(map, data);
|
|
27
|
+
if (result) {
|
|
28
|
+
var handleError = validationContext.get(handler).handleError;
|
|
29
|
+
return handleError ? innet__default["default"](handleError(result), handler) : undefined;
|
|
30
|
+
}
|
|
31
|
+
return innet__default["default"](children, handler);
|
|
33
32
|
};
|
|
34
33
|
if (resource === 'body' || resource === 'files') {
|
|
35
34
|
return action.parseBody().then(run);
|