adminizer 4.3.0-build.126 → 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";
@@ -191,6 +191,13 @@ export interface AdminpanelConfig {
191
191
  notifications?: {
192
192
  enabled: boolean;
193
193
  };
194
+ cors?: {
195
+ enabled: boolean;
196
+ origin?: string[];
197
+ credentials?: boolean;
198
+ methods?: string[];
199
+ allowedHeaders?: string[];
200
+ };
194
201
  }
195
202
  export interface ModelConfig {
196
203
  adapter?: string;
package/lib/Adminizer.js CHANGED
@@ -150,16 +150,9 @@ export class Adminizer {
150
150
  chalk.blue('\nAccess your app at http://localhost:3000'));
151
151
  }
152
152
  async init(config) {
153
- // set cookie parser
154
- this.app.use(cookieParser());
155
153
  if (!config || Object.keys(config).length === 0) {
156
154
  Adminizer.log.warn(`Adminizer init > Adminizer config is emtpy`);
157
155
  }
158
- // Set vite middleware
159
- const isViteDev = process.env.VITE_ENV === "dev";
160
- if (isViteDev)
161
- await this.viteMiddleware();
162
- this.emitter.emit('adminizer:init');
163
156
  if (this.config && Object.keys(this.config).length > 0) {
164
157
  throw new Error("Config has already been initialized");
165
158
  }
@@ -184,6 +177,48 @@ export class Adminizer {
184
177
  set: configForms.set ?? defaultForms.set
185
178
  }
186
179
  };
180
+ // Middleware для всех API маршрутов
181
+ const defaultOrigin = process.env.FRONTEND_URL || 'http://localhost:8080';
182
+ if (config?.cors?.enabled) {
183
+ const corsConfig = config.cors;
184
+ // Поддерживаем массив разрешенных origin
185
+ const allowedOrigins = Array.isArray(corsConfig.origin)
186
+ ? corsConfig.origin
187
+ : [corsConfig.origin || defaultOrigin];
188
+ this.app.all(`${this.config.routePrefix}/api/*`, (req, res, next) => {
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
+ }
208
+ if (req.method === 'OPTIONS') {
209
+ return res.status(200).end();
210
+ }
211
+ next();
212
+ });
213
+ console.log('✅ API CORS middleware enabled. Allowed origins:', allowedOrigins);
214
+ }
215
+ // set cookie parser
216
+ this.app.use(cookieParser());
217
+ // Set vite middleware
218
+ const isViteDev = process.env.VITE_ENV === "dev";
219
+ if (isViteDev)
220
+ await this.viteMiddleware();
221
+ this.emitter.emit('adminizer:init');
187
222
  this.modelHandler = new ModelHandler();
188
223
  // TODO: 'hot reload' unbind models & unbind forms
189
224
  await bindModels(this);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "4.3.0-build.126",
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",
@@ -102,7 +102,7 @@ export function bindInertia(adminizer) {
102
102
  enabled: true,
103
103
  cookieName: 'XSRF-TOKEN',
104
104
  headerName: 'x-xsrf-token'
105
- },
105
+ }
106
106
  }));
107
107
  adminizer.app.use((req, _, next) => {
108
108
  checkAuth(req, adminizer);
@@ -141,6 +141,9 @@ let adminpanelConfig = {
141
141
  notifications: {
142
142
  enabled: false
143
143
  },
144
+ cors: {
145
+ enabled: false,
146
+ },
144
147
  mediamanager: {
145
148
  fileStoragePath: '.tmp/public',
146
149
  }