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.
- package/lib/Adminizer.js +32 -10
- 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
|
|
79
|
-
|
|
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
|
-
|
|
82
|
-
|
|
90
|
+
condition1,
|
|
91
|
+
condition2
|
|
83
92
|
];
|
|
84
93
|
if (process.env.IS_SAILS === undefined) {
|
|
85
|
-
conditions.push(
|
|
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.
|
|
99
|
-
|
|
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.
|
|
106
|
-
|
|
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
|
};
|