adminizer 4.3.0-build.127 → 4.3.0-build.128
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 +25 -8
- package/package.json +2 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/lib/Adminizer.js
CHANGED
|
@@ -178,22 +178,39 @@ 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
|
+
return res.status(200).end();
|
|
196
|
+
}
|
|
197
|
+
return next();
|
|
198
|
+
}
|
|
199
|
+
// Запрос с разрешенного origin или без Origin
|
|
200
|
+
if (isOriginAllowed) {
|
|
201
|
+
// Для CORS запросов возвращаем тот же origin (или первый из списка)
|
|
202
|
+
const allowOrigin = requestOrigin || allowedOrigins[0];
|
|
203
|
+
res.header('Access-Control-Allow-Origin', allowOrigin);
|
|
204
|
+
res.header('Access-Control-Allow-Credentials', corsConfig.credentials !== false ? 'true' : 'false');
|
|
205
|
+
res.header('Access-Control-Allow-Methods', corsConfig.methods?.join(',') || 'GET,POST,PUT,DELETE,OPTIONS');
|
|
206
|
+
res.header('Access-Control-Allow-Headers', corsConfig.allowedHeaders?.join(',') || 'Content-Type,Authorization,X-Requested-With,X-CSRF-Token,x-xsrf-token');
|
|
207
|
+
}
|
|
191
208
|
if (req.method === 'OPTIONS') {
|
|
192
209
|
return res.status(200).end();
|
|
193
210
|
}
|
|
194
211
|
next();
|
|
195
212
|
});
|
|
196
|
-
console.log('✅
|
|
213
|
+
console.log('✅ API CORS middleware enabled. Allowed origins:', allowedOrigins);
|
|
197
214
|
}
|
|
198
215
|
// set cookie parser
|
|
199
216
|
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.128",
|
|
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:4173 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",
|