@aeriajs/http 0.0.37 → 0.0.39
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 +20 -13
- package/dist/routing.mjs +9 -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,12 +24,13 @@ const unsufficientRoles = (context) => {
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
const matches = (req, method, exp, options, config) => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
|
|
27
|
+
const base = config?.apiBase && config.apiBase !== '/'
|
|
28
|
+
? options.base
|
|
29
|
+
? `${config.apiBase}${options.base}`
|
|
30
|
+
: config.apiBase
|
|
31
|
+
: options.base
|
|
32
|
+
? options.base
|
|
33
|
+
: '';
|
|
33
34
|
if (method && method !== req.method) {
|
|
34
35
|
if (!Array.isArray(method) || !method.includes(req.method)) {
|
|
35
36
|
return;
|
|
@@ -38,9 +39,10 @@ const matches = (req, method, exp, options, config) => {
|
|
|
38
39
|
const regexp = exp instanceof RegExp
|
|
39
40
|
? exp
|
|
40
41
|
: new RegExp(`^${base}${exp}$`);
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const url = new URL(`http://0.com${req.url}`).pathname;
|
|
43
|
+
const expMatches = url.match(regexp);
|
|
44
|
+
if (expMatches) {
|
|
45
|
+
const fragments = expMatches.splice(1);
|
|
44
46
|
return {
|
|
45
47
|
fragments,
|
|
46
48
|
};
|
|
@@ -166,10 +168,15 @@ const createRouter = (options = {}) => {
|
|
|
166
168
|
}
|
|
167
169
|
routes.push(async (_, context, groupOptions) => {
|
|
168
170
|
const config = await (0, entrypoint_1.getConfig)();
|
|
169
|
-
|
|
170
|
-
?
|
|
171
|
-
:
|
|
172
|
-
|
|
171
|
+
const base = groupOptions
|
|
172
|
+
? groupOptions.base
|
|
173
|
+
: options.base;
|
|
174
|
+
newOptions.base = base && base !== '/'
|
|
175
|
+
? `${base}${exp}`
|
|
176
|
+
: exp;
|
|
177
|
+
const match = (0, exports.matches)(context.request, null, config.apiBase === '/'
|
|
178
|
+
? new RegExp(`^${newOptions.base}/`)
|
|
179
|
+
: new RegExp(`^${config.apiBase}${newOptions.base}/`), newOptions);
|
|
173
180
|
if (match) {
|
|
174
181
|
if (middleware) {
|
|
175
182
|
const result = await middleware(context);
|
package/dist/routing.mjs
CHANGED
|
@@ -22,17 +22,17 @@ const unsufficientRoles = (context) => {
|
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
export const matches = (req, method, exp, options, config) => {
|
|
25
|
-
const
|
|
26
|
-
const base = `${config.apiBase}${options.base ? `/${options.base}` : ""}`.replace("//", "/").replace(/\/$/, "");
|
|
25
|
+
const base = config?.apiBase && config.apiBase !== "/" ? options.base ? `${config.apiBase}${options.base}` : config.apiBase : options.base ? options.base : "";
|
|
27
26
|
if (method && method !== req.method) {
|
|
28
27
|
if (!Array.isArray(method) || !method.includes(req.method)) {
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
const regexp = exp instanceof RegExp ? exp : new RegExp(`^${base}${exp}$`);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const url = new URL(`http://0.com${req.url}`).pathname;
|
|
33
|
+
const expMatches = url.match(regexp);
|
|
34
|
+
if (expMatches) {
|
|
35
|
+
const fragments = expMatches.splice(1);
|
|
36
36
|
return {
|
|
37
37
|
fragments
|
|
38
38
|
};
|
|
@@ -164,13 +164,13 @@ export const createRouter = (options = {}) => {
|
|
|
164
164
|
}
|
|
165
165
|
routes.push(async (_, context, groupOptions) => {
|
|
166
166
|
const config = await getConfig();
|
|
167
|
-
|
|
167
|
+
const base = groupOptions ? groupOptions.base : options.base;
|
|
168
|
+
newOptions.base = base && base !== "/" ? `${base}${exp}` : exp;
|
|
168
169
|
const match = matches(
|
|
169
170
|
context.request,
|
|
170
171
|
null,
|
|
171
|
-
new RegExp(`^${newOptions.base}/`),
|
|
172
|
-
newOptions
|
|
173
|
-
config
|
|
172
|
+
config.apiBase === "/" ? new RegExp(`^${newOptions.base}/`) : new RegExp(`^${config.apiBase}${newOptions.base}/`),
|
|
173
|
+
newOptions
|
|
174
174
|
);
|
|
175
175
|
if (match) {
|
|
176
176
|
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.39",
|
|
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",
|