ag-common 0.0.148 → 0.0.149
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/dist/ui/helpers/routes.d.ts +19 -5
- package/dist/ui/helpers/routes.js +17 -11
- package/package.json +1 -1
|
@@ -77,6 +77,24 @@ export declare const getClientOrServerReqHref: ({ href, query, }: {
|
|
|
77
77
|
*/
|
|
78
78
|
query?: Record<string, string> | undefined;
|
|
79
79
|
}) => LocationSubset;
|
|
80
|
+
/**
|
|
81
|
+
* get server side parsed url
|
|
82
|
+
* @param param0 * @returns
|
|
83
|
+
*/
|
|
84
|
+
export declare const getServerReq: ({ host, pathname, query, }: {
|
|
85
|
+
/**
|
|
86
|
+
* eg ctx?.req?.headers?.host
|
|
87
|
+
*/
|
|
88
|
+
host: string;
|
|
89
|
+
/**
|
|
90
|
+
* eg ctx.asPath || '/'
|
|
91
|
+
*/
|
|
92
|
+
pathname: string;
|
|
93
|
+
/**
|
|
94
|
+
* eg ctx.query
|
|
95
|
+
*/
|
|
96
|
+
query: Record<string, string | string[] | undefined>;
|
|
97
|
+
}) => LocationSubset;
|
|
80
98
|
export interface INextCtx {
|
|
81
99
|
req?: {
|
|
82
100
|
headers?: {
|
|
@@ -86,8 +104,4 @@ export interface INextCtx {
|
|
|
86
104
|
asPath?: string;
|
|
87
105
|
query: Record<string, string | string[] | undefined>;
|
|
88
106
|
}
|
|
89
|
-
|
|
90
|
-
* get parsed url from nextjs server host/pathname/query
|
|
91
|
-
* @param param0 * @returns
|
|
92
|
-
*/
|
|
93
|
-
export declare const getServerReq: (ctx: INextCtx) => LocationSubset | null;
|
|
107
|
+
export declare const getServerReqNextJs: (ctx: INextCtx) => LocationSubset | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getServerReq = exports.getClientOrServerReqHref = void 0;
|
|
3
|
+
exports.getServerReqNextJs = exports.getServerReq = exports.getClientOrServerReqHref = void 0;
|
|
4
4
|
const url_1 = require("url");
|
|
5
5
|
const string_1 = require("../../common/helpers/string");
|
|
6
6
|
const object_1 = require("../../common/helpers/object");
|
|
@@ -45,22 +45,28 @@ const getClientOrServerReqHref = ({ href, query, }) => {
|
|
|
45
45
|
};
|
|
46
46
|
exports.getClientOrServerReqHref = getClientOrServerReqHref;
|
|
47
47
|
/**
|
|
48
|
-
* get parsed url
|
|
48
|
+
* get server side parsed url
|
|
49
49
|
* @param param0 * @returns
|
|
50
50
|
*/
|
|
51
|
-
const getServerReq = (
|
|
52
|
-
var _a, _b;
|
|
53
|
-
if (!((_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.req) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.host) || !(ctx === null || ctx === void 0 ? void 0 : ctx.asPath)) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
51
|
+
const getServerReq = ({ host, pathname, query, }) => {
|
|
56
52
|
const href = calculateServerHref({
|
|
57
|
-
host
|
|
58
|
-
pathname
|
|
53
|
+
host,
|
|
54
|
+
pathname,
|
|
59
55
|
});
|
|
60
|
-
const parsedQuery = !
|
|
56
|
+
const parsedQuery = !query || Object.keys(query).length === 0
|
|
61
57
|
? undefined
|
|
62
|
-
: (0, object_1.castStringlyObject)(
|
|
58
|
+
: (0, object_1.castStringlyObject)(query);
|
|
63
59
|
const ret = (0, exports.getClientOrServerReqHref)({ href, query: parsedQuery });
|
|
64
60
|
return ret;
|
|
65
61
|
};
|
|
66
62
|
exports.getServerReq = getServerReq;
|
|
63
|
+
const getServerReqNextJs = (ctx) => {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const host = (_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.req) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.host;
|
|
66
|
+
const pathname = ctx === null || ctx === void 0 ? void 0 : ctx.asPath;
|
|
67
|
+
if (!host || !pathname) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return (0, exports.getServerReq)({ host, pathname, query: ctx.query });
|
|
71
|
+
};
|
|
72
|
+
exports.getServerReqNextJs = getServerReqNextJs;
|