adminizer 4.3.0-build.84 → 4.3.0-build.85

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.
Files changed (2) hide show
  1. package/lib/Adminizer.js +32 -10
  2. package/package.json +1 -1
package/lib/Adminizer.js CHANGED
@@ -74,36 +74,58 @@ export class Adminizer {
74
74
  return (req, res, next) => {
75
75
  try {
76
76
  const prefix = (this.config && this.config.routePrefix) ? String(this.config.routePrefix) : '';
77
+ if (prefix === '/') {
78
+ throw new Error('Using "/" as routePrefix is temporarily prohibited');
79
+ }
77
80
  const normalizedPrefix = prefix.replace(/\/+/g, '/').replace(/\/+$/g, '');
78
- if (normalizedPrefix) {
79
- const url = req.url || req.originalUrl || '';
81
+ // Check if this middleware is already mounted under a prefix
82
+ const isMountedUnderPrefix = req.baseUrl && req.baseUrl === normalizedPrefix;
83
+ if (normalizedPrefix && !isMountedUnderPrefix) {
84
+ // Legacy behavior: middleware not mounted under prefix, check URL manually
85
+ const url = req.originalUrl || req.url || '';
86
+ const condition1 = url === normalizedPrefix;
87
+ const condition2 = url.startsWith(normalizedPrefix + '/');
88
+ const condition3 = url.startsWith('/public');
80
89
  const conditions = [
81
- url === normalizedPrefix,
82
- url.startsWith(normalizedPrefix + '/')
90
+ condition1,
91
+ condition2
83
92
  ];
84
93
  if (process.env.IS_SAILS === undefined) {
85
- conditions.push(url.startsWith('/public'));
94
+ conditions.push(condition3);
86
95
  }
87
96
  if (!conditions.some(condition => condition)) {
88
97
  return typeof next === 'function' ? next() : undefined;
89
98
  }
90
99
  }
100
+ else if (isMountedUnderPrefix) {
101
+ // When mounted under prefix, we need to restore the full path for internal routing
102
+ // because Router expects routes with full prefix
103
+ const originalUrl = req.url;
104
+ req.url = normalizedPrefix + req.url;
105
+ }
106
+ else {
107
+ // No prefix configured, handling all requests
108
+ }
91
109
  }
92
110
  catch (e) {
93
111
  // fall back to handling the request
94
112
  }
95
113
  this.app(req, res, (err) => {
96
114
  if (err) {
97
- console.error("Error in Adminizer", err);
98
- res.writeHead(500, { 'Content-Type': 'text/plain' });
99
- res.end('Internal Server Error');
115
+ console.error("Error in Adminizer:", err);
116
+ if (!res.headersSent) {
117
+ res.writeHead(500, { 'Content-Type': 'text/plain' });
118
+ res.end('Internal Server Error');
119
+ }
100
120
  }
101
121
  else {
102
122
  if (typeof next === 'function') {
103
123
  return next();
104
124
  }
105
- res.writeHead(404, { 'Content-Type': 'text/plain' });
106
- res.end('Route Not Found in Adminizer');
125
+ if (!res.headersSent) {
126
+ res.writeHead(404, { 'Content-Type': 'text/plain' });
127
+ res.end('Route Not Found in Adminizer');
128
+ }
107
129
  }
108
130
  });
109
131
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "4.3.0-build.84",
4
+ "version": "4.3.0-build.85",
5
5
  "main": "index.js",
6
6
  "exports": {
7
7
  ".": "./index.js",