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 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,39 @@ 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
+ 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('✅ API CORS middleware enabled');
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.127",
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",