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 CHANGED
@@ -27,3 +27,4 @@ export * from "./models/MediaManagerMetaAP";
27
27
  export * from "./models/NavigationAP";
28
28
  export * from "./migrations";
29
29
  export * from "./system/bindNavigation";
30
+ export * from "./lib/helper/jwt";
package/index.js CHANGED
@@ -27,3 +27,4 @@ export * from "./models/MediaManagerMetaAP";
27
27
  export * from "./models/NavigationAP";
28
28
  export * from "./migrations";
29
29
  export * from "./system/bindNavigation";
30
+ export * from "./lib/helper/jwt";
@@ -193,7 +193,7 @@ export interface AdminpanelConfig {
193
193
  };
194
194
  cors?: {
195
195
  enabled: boolean;
196
- origin?: string;
196
+ origin?: string[];
197
197
  credentials?: boolean;
198
198
  methods?: string[];
199
199
  allowedHeaders?: string[];
package/lib/Adminizer.js CHANGED
@@ -178,22 +178,45 @@ export class Adminizer {
178
178
  }
179
179
  };
180
180
  // Middleware для всех API маршрутов
181
- const allowedOrigin = process.env.FRONTEND_URL || 'http://localhost:8080';
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
- // Устанавливаем CORS заголовки
186
- res.header('Access-Control-Allow-Origin', corsConfig.origin || allowedOrigin);
187
- res.header('Access-Control-Allow-Credentials', corsConfig.credentials !== false ? 'true' : 'false');
188
- res.header('Access-Control-Allow-Methods', corsConfig.methods?.join(',') || 'GET,POST,PUT,DELETE,OPTIONS');
189
- res.header('Access-Control-Allow-Headers', corsConfig.allowedHeaders?.join(',') || 'Content-Type,Authorization,X-Requested-With,X-CSRF-Token,x-xsrf-token');
190
- // Если это OPTIONS запрос - сразу отвечаем
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('✅ API CORS middleware enabled');
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.127",
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",