@aeriajs/http 0.0.37 → 0.0.38
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/routing.d.ts +1 -1
- package/dist/routing.js +19 -11
- package/dist/routing.mjs +16 -9
- package/package.json +11 -11
package/dist/routing.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type ProxiedRouter<TRouter> = TRouter & Record<RequestMethod, <const TCon
|
|
|
25
25
|
authenticated: true;
|
|
26
26
|
};
|
|
27
27
|
}) => Response : never : (context: TypedContext<TContractWithRoles>) => Response : never>(exp: RouteUri, cb: TCallback, contract?: TContractWithRoles) => ReturnType<typeof registerRoute>>;
|
|
28
|
-
export declare const matches: <TRequest extends GenericRequest>(req: TRequest, method: RequestMethod | RequestMethod[] | null, exp: string | RegExp, options: RouterOptions, config
|
|
28
|
+
export declare const matches: <TRequest extends GenericRequest>(req: TRequest, method: RequestMethod | RequestMethod[] | null, exp: string | RegExp, options: RouterOptions, config?: ApiConfig) => {
|
|
29
29
|
fragments: string[];
|
|
30
30
|
} | undefined;
|
|
31
31
|
export declare const registerRoute: (context: RouteContext, method: RequestMethod | RequestMethod[], exp: RouteUri, cb: (context: RouteContext) => any, contract?: ContractWithRoles, options?: RouterOptions) => Promise<any>;
|
package/dist/routing.js
CHANGED
|
@@ -24,10 +24,14 @@ const unsufficientRoles = (context) => {
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
const matches = (req, method, exp, options, config) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
let base = '';
|
|
28
|
+
if (config?.apiBase) {
|
|
29
|
+
base += config.apiBase;
|
|
30
|
+
}
|
|
31
|
+
if (options.base) {
|
|
32
|
+
base += `/${options.base}`;
|
|
33
|
+
}
|
|
34
|
+
base = base
|
|
31
35
|
.replace('//', '/')
|
|
32
36
|
.replace(/\/$/, '');
|
|
33
37
|
if (method && method !== req.method) {
|
|
@@ -38,9 +42,10 @@ const matches = (req, method, exp, options, config) => {
|
|
|
38
42
|
const regexp = exp instanceof RegExp
|
|
39
43
|
? exp
|
|
40
44
|
: new RegExp(`^${base}${exp}$`);
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const url = new URL(`http://0.com${req.url}`).pathname;
|
|
46
|
+
const expMatches = url.match(regexp);
|
|
47
|
+
if (expMatches) {
|
|
48
|
+
const fragments = expMatches.splice(1);
|
|
44
49
|
return {
|
|
45
50
|
fragments,
|
|
46
51
|
};
|
|
@@ -166,10 +171,13 @@ const createRouter = (options = {}) => {
|
|
|
166
171
|
}
|
|
167
172
|
routes.push(async (_, context, groupOptions) => {
|
|
168
173
|
const config = await (0, entrypoint_1.getConfig)();
|
|
169
|
-
|
|
170
|
-
?
|
|
171
|
-
:
|
|
172
|
-
|
|
174
|
+
const base = groupOptions
|
|
175
|
+
? groupOptions.base
|
|
176
|
+
: options.base;
|
|
177
|
+
newOptions.base = base
|
|
178
|
+
? `${base}${exp}`
|
|
179
|
+
: exp;
|
|
180
|
+
const match = (0, exports.matches)(context.request, null, new RegExp(`^${config.apiBase}${newOptions.base}/`), newOptions);
|
|
173
181
|
if (match) {
|
|
174
182
|
if (middleware) {
|
|
175
183
|
const result = await middleware(context);
|
package/dist/routing.mjs
CHANGED
|
@@ -22,17 +22,24 @@ const unsufficientRoles = (context) => {
|
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
export const matches = (req, method, exp, options, config) => {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
let base = "";
|
|
26
|
+
if (config?.apiBase) {
|
|
27
|
+
base += config.apiBase;
|
|
28
|
+
}
|
|
29
|
+
if (options.base) {
|
|
30
|
+
base += `/${options.base}`;
|
|
31
|
+
}
|
|
32
|
+
base = base.replace("//", "/").replace(/\/$/, "");
|
|
27
33
|
if (method && method !== req.method) {
|
|
28
34
|
if (!Array.isArray(method) || !method.includes(req.method)) {
|
|
29
35
|
return;
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
const regexp = exp instanceof RegExp ? exp : new RegExp(`^${base}${exp}$`);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
const url = new URL(`http://0.com${req.url}`).pathname;
|
|
40
|
+
const expMatches = url.match(regexp);
|
|
41
|
+
if (expMatches) {
|
|
42
|
+
const fragments = expMatches.splice(1);
|
|
36
43
|
return {
|
|
37
44
|
fragments
|
|
38
45
|
};
|
|
@@ -164,13 +171,13 @@ export const createRouter = (options = {}) => {
|
|
|
164
171
|
}
|
|
165
172
|
routes.push(async (_, context, groupOptions) => {
|
|
166
173
|
const config = await getConfig();
|
|
167
|
-
|
|
174
|
+
const base = groupOptions ? groupOptions.base : options.base;
|
|
175
|
+
newOptions.base = base ? `${base}${exp}` : exp;
|
|
168
176
|
const match = matches(
|
|
169
177
|
context.request,
|
|
170
178
|
null,
|
|
171
|
-
new RegExp(`^${newOptions.base}/`),
|
|
172
|
-
newOptions
|
|
173
|
-
config
|
|
179
|
+
new RegExp(`^${config.apiBase}${newOptions.base}/`),
|
|
180
|
+
newOptions
|
|
174
181
|
);
|
|
175
182
|
if (match) {
|
|
176
183
|
if (middleware) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/http",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -22,18 +22,18 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@aeriajs/access-control": "^0.0.
|
|
26
|
-
"@aeriajs/common": "^0.0.
|
|
27
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
28
|
-
"@aeriajs/types": "^0.0.
|
|
29
|
-
"@aeriajs/validation": "^0.0.
|
|
25
|
+
"@aeriajs/access-control": "^0.0.31",
|
|
26
|
+
"@aeriajs/common": "^0.0.31",
|
|
27
|
+
"@aeriajs/entrypoint": "^0.0.31",
|
|
28
|
+
"@aeriajs/types": "^0.0.28",
|
|
29
|
+
"@aeriajs/validation": "^0.0.34"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@aeriajs/access-control": "^0.0.
|
|
33
|
-
"@aeriajs/common": "^0.0.
|
|
34
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
35
|
-
"@aeriajs/types": "^0.0.
|
|
36
|
-
"@aeriajs/validation": "^0.0.
|
|
32
|
+
"@aeriajs/access-control": "^0.0.31",
|
|
33
|
+
"@aeriajs/common": "^0.0.31",
|
|
34
|
+
"@aeriajs/entrypoint": "^0.0.31",
|
|
35
|
+
"@aeriajs/types": "^0.0.28",
|
|
36
|
+
"@aeriajs/validation": "^0.0.34"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"test": "echo skipping",
|