@aeriajs/http 0.0.38 → 0.0.40

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.js CHANGED
@@ -24,16 +24,13 @@ const unsufficientRoles = (context) => {
24
24
  };
25
25
  };
26
26
  const matches = (req, method, exp, options, config) => {
27
- let base = '';
28
- if (config?.apiBase) {
29
- base += config.apiBase;
30
- }
31
- if (options.base) {
32
- base += `/${options.base}`;
33
- }
34
- base = base
35
- .replace('//', '/')
36
- .replace(/\/$/, '');
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
+ : '';
37
34
  if (method && method !== req.method) {
38
35
  if (!Array.isArray(method) || !method.includes(req.method)) {
39
36
  return;
@@ -174,10 +171,12 @@ const createRouter = (options = {}) => {
174
171
  const base = groupOptions
175
172
  ? groupOptions.base
176
173
  : options.base;
177
- newOptions.base = base
174
+ newOptions.base = base && base !== '/'
178
175
  ? `${base}${exp}`
179
176
  : exp;
180
- const match = (0, exports.matches)(context.request, null, new RegExp(`^${config.apiBase}${newOptions.base}/`), newOptions);
177
+ const match = (0, exports.matches)(context.request, null, config.apiBase === '/'
178
+ ? new RegExp(`^${newOptions.base}/`)
179
+ : new RegExp(`^${config.apiBase}${newOptions.base}/`), newOptions);
181
180
  if (match) {
182
181
  if (middleware) {
183
182
  const result = await middleware(context);
package/dist/routing.mjs CHANGED
@@ -22,14 +22,7 @@ const unsufficientRoles = (context) => {
22
22
  };
23
23
  };
24
24
  export const matches = (req, method, exp, options, config) => {
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(/\/$/, "");
25
+ const base = config?.apiBase && config.apiBase !== "/" ? options.base ? `${config.apiBase}${options.base}` : config.apiBase : options.base ? options.base : "";
33
26
  if (method && method !== req.method) {
34
27
  if (!Array.isArray(method) || !method.includes(req.method)) {
35
28
  return;
@@ -172,11 +165,11 @@ export const createRouter = (options = {}) => {
172
165
  routes.push(async (_, context, groupOptions) => {
173
166
  const config = await getConfig();
174
167
  const base = groupOptions ? groupOptions.base : options.base;
175
- newOptions.base = base ? `${base}${exp}` : exp;
168
+ newOptions.base = base && base !== "/" ? `${base}${exp}` : exp;
176
169
  const match = matches(
177
170
  context.request,
178
171
  null,
179
- new RegExp(`^${config.apiBase}${newOptions.base}/`),
172
+ config.apiBase === "/" ? new RegExp(`^${newOptions.base}/`) : new RegExp(`^${config.apiBase}${newOptions.base}/`),
180
173
  newOptions
181
174
  );
182
175
  if (match) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/http",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
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.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"
25
+ "@aeriajs/access-control": "^0.0.32",
26
+ "@aeriajs/common": "^0.0.32",
27
+ "@aeriajs/entrypoint": "^0.0.32",
28
+ "@aeriajs/types": "^0.0.29",
29
+ "@aeriajs/validation": "^0.0.35"
30
30
  },
31
31
  "peerDependencies": {
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"
32
+ "@aeriajs/access-control": "^0.0.32",
33
+ "@aeriajs/common": "^0.0.32",
34
+ "@aeriajs/entrypoint": "^0.0.32",
35
+ "@aeriajs/types": "^0.0.29",
36
+ "@aeriajs/validation": "^0.0.35"
37
37
  },
38
38
  "scripts": {
39
39
  "test": "echo skipping",