adminizer 4.3.0-build.127 → 4.3.0-build.129
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/index.d.ts +1 -0
- package/index.js +1 -0
- package/interfaces/adminpanelConfig.d.ts +1 -1
- package/lib/Adminizer.js +31 -8
- package/package.json +2 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/lib/Adminizer.js
CHANGED
|
@@ -178,22 +178,45 @@ export class Adminizer {
|
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
180
|
// Middleware для всех API маршрутов
|
|
181
|
-
const
|
|
181
|
+
const defaultOrigin = process.env.FRONTEND_URL || 'http://localhost:8080';
|
|
182
182
|
if (config?.cors?.enabled) {
|
|
183
183
|
const corsConfig = config.cors;
|
|
184
|
+
// Поддерживаем массив разрешенных origin
|
|
185
|
+
const allowedOrigins = Array.isArray(corsConfig.origin)
|
|
186
|
+
? corsConfig.origin
|
|
187
|
+
: [corsConfig.origin || defaultOrigin];
|
|
184
188
|
this.app.all(`${this.config.routePrefix}/api/*`, (req, res, next) => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
const requestOrigin = req.headers.origin;
|
|
190
|
+
// Проверяем разрешен ли origin
|
|
191
|
+
const isOriginAllowed = !requestOrigin || allowedOrigins.includes(requestOrigin);
|
|
192
|
+
if (requestOrigin && !isOriginAllowed) {
|
|
193
|
+
console.log(`❌ CORS: Blocked request from ${requestOrigin}`);
|
|
194
|
+
if (req.method === 'OPTIONS') {
|
|
195
|
+
// Для preflight - 200 без CORS headers
|
|
196
|
+
return res.status(200).end();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// Для основных запросов - ошибка
|
|
200
|
+
return res.status(403).json({
|
|
201
|
+
error: 'CORS policy: Origin not allowed'
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Запрос с разрешенного origin или без Origin
|
|
206
|
+
if (isOriginAllowed) {
|
|
207
|
+
// Для CORS запросов возвращаем тот же origin (или первый из списка)
|
|
208
|
+
const allowOrigin = requestOrigin || allowedOrigins[0];
|
|
209
|
+
res.header('Access-Control-Allow-Origin', allowOrigin);
|
|
210
|
+
res.header('Access-Control-Allow-Credentials', corsConfig.credentials !== false ? 'true' : 'false');
|
|
211
|
+
res.header('Access-Control-Allow-Methods', corsConfig.methods?.join(',') || 'GET,POST,PUT,DELETE,OPTIONS');
|
|
212
|
+
res.header('Access-Control-Allow-Headers', corsConfig.allowedHeaders?.join(',') || 'Content-Type,Authorization,X-Requested-With,X-CSRF-Token,x-xsrf-token');
|
|
213
|
+
}
|
|
191
214
|
if (req.method === 'OPTIONS') {
|
|
192
215
|
return res.status(200).end();
|
|
193
216
|
}
|
|
194
217
|
next();
|
|
195
218
|
});
|
|
196
|
-
console.log('✅
|
|
219
|
+
console.log('✅ API CORS middleware enabled. Allowed origins:', allowedOrigins);
|
|
197
220
|
}
|
|
198
221
|
// set cookie parser
|
|
199
222
|
this.app.use(cookieParser());
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adminizer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.3.0-build.
|
|
4
|
+
"version": "4.3.0-build.129",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./index.js",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"dev:no-seed-clean": "cross-env VITE_ENV=dev NO_SEED_DATA=true CLEAN_TMP=true ORM=sequelize tsx watch --tsconfig ./fixture/tsconfig.json ./fixture/index.ts",
|
|
17
17
|
"dev:waterline": "cross-env VITE_ENV=dev ORM=waterline tsx watch --tsconfig ./fixture/tsconfig.json ./fixture/index.ts",
|
|
18
18
|
"dev:waterline:no-seed": "cross-env VITE_ENV=dev NO_SEED_DATA=true ORM=waterline tsx watch --tsconfig ./fixture/tsconfig.json ./fixture/index.ts",
|
|
19
|
+
"dev:cors": "cross-env VITE_ENV=dev NO_SEED_DATA=true ORM=waterline FRONTEND_URL=http://localhost:8080 tsx watch --tsconfig ./fixture/tsconfig.json ./fixture/index.ts",
|
|
19
20
|
"build:assets": "vite build",
|
|
20
21
|
"compile:backend": "tsc -p src/tsconfig.json",
|
|
21
22
|
"compile:ui": "tsc -p tsconfig.ui.json",
|