adminizer 4.2.0-build.63 → 4.2.0-build.64

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.
@@ -1,4 +1,4 @@
1
- import { Express } from "express";
1
+ import express, { Express } from "express";
2
2
  import winston from "winston";
3
3
  import EventEmitter from 'events';
4
4
  import { AdminpanelConfig } from "../interfaces/adminpanelConfig";
@@ -34,7 +34,7 @@ export declare class Adminizer {
34
34
  jwtSecret: string;
35
35
  static logger: winston.Logger;
36
36
  constructor(ormAdapters: AbstractAdapter[]);
37
- getMiddleware(): (req: any, res: any) => void;
37
+ getMiddleware(): (req: express.Request, res: express.Response, next: () => void) => void;
38
38
  /**
39
39
  * Vite middleware
40
40
  * @protected
package/lib/Adminizer.js CHANGED
@@ -69,14 +69,34 @@ export class Adminizer {
69
69
  this.ormAdapters = ormAdapters;
70
70
  }
71
71
  getMiddleware() {
72
- return (req, res) => {
72
+ return (req, res, next) => {
73
+ // If a routePrefix is configured, only handle requests that match it.
74
+ try {
75
+ const prefix = (this.config && this.config.routePrefix) ? String(this.config.routePrefix) : '';
76
+ const normalizedPrefix = prefix.replace(/\/+/g, '/').replace(/\/+$/g, '');
77
+ if (normalizedPrefix) {
78
+ const url = req.url || req.originalUrl || '';
79
+ if (!(url === normalizedPrefix || url.startsWith(normalizedPrefix + '/'))) {
80
+ // Not an admin route — pass to next middleware
81
+ return typeof next === 'function' ? next() : undefined;
82
+ }
83
+ }
84
+ }
85
+ catch (e) {
86
+ // If anything goes wrong while checking, fall back to handling the request
87
+ }
73
88
  this.app(req, res, (err) => {
74
89
  if (err) {
90
+ // eslint-disable-next-line no-console
75
91
  console.error("Error in Adminizer", err);
76
92
  res.writeHead(500, { 'Content-Type': 'text/plain' });
77
93
  res.end('Internal Server Error');
78
94
  }
79
95
  else {
96
+ // If Adminizer didn't handle the route, let the rest of the stack try
97
+ if (typeof next === 'function') {
98
+ return next();
99
+ }
80
100
  res.writeHead(404, { 'Content-Type': 'text/plain' });
81
101
  res.end('Route Not Found in Adminizer');
82
102
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "4.2.0-build.63",
4
+ "version": "4.2.0-build.64",
5
5
  "main": "index.js",
6
6
  "exports": {
7
7
  ".": "./index.js",