adminizer 4.2.0-build.66 → 4.2.0-build.68

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.
@@ -173,6 +173,9 @@ export interface AdminpanelConfig {
173
173
  /** Default ORM adapter for system models */
174
174
  defaultORM: string;
175
175
  };
176
+ bind?: {
177
+ public: boolean;
178
+ };
176
179
  }
177
180
  export interface ModelConfig {
178
181
  adapter?: string;
package/lib/Adminizer.js CHANGED
@@ -70,30 +70,33 @@ export class Adminizer {
70
70
  }
71
71
  getMiddleware() {
72
72
  return (req, res, next) => {
73
- // If a routePrefix is configured, only handle requests that match it.
74
73
  try {
75
74
  const prefix = (this.config && this.config.routePrefix) ? String(this.config.routePrefix) : '';
76
75
  const normalizedPrefix = prefix.replace(/\/+/g, '/').replace(/\/+$/g, '');
77
76
  if (normalizedPrefix) {
78
77
  const url = req.url || req.originalUrl || '';
79
- if (!(url === normalizedPrefix || url.startsWith(normalizedPrefix + '/') || url.startsWith('/public'))) {
80
- // Not an admin route — pass to next middleware
78
+ const conditions = [
79
+ url === normalizedPrefix,
80
+ url.startsWith(normalizedPrefix + '/')
81
+ ];
82
+ if (process.env.IS_SAILS === undefined) {
83
+ conditions.push(url.startsWith('/public'));
84
+ }
85
+ if (!conditions.some(condition => condition)) {
81
86
  return typeof next === 'function' ? next() : undefined;
82
87
  }
83
88
  }
84
89
  }
85
90
  catch (e) {
86
- // If anything goes wrong while checking, fall back to handling the request
91
+ // fall back to handling the request
87
92
  }
88
93
  this.app(req, res, (err) => {
89
94
  if (err) {
90
- // eslint-disable-next-line no-console
91
95
  console.error("Error in Adminizer", err);
92
96
  res.writeHead(500, { 'Content-Type': 'text/plain' });
93
97
  res.end('Internal Server Error');
94
98
  }
95
99
  else {
96
- // If Adminizer didn't handle the route, let the rest of the stack try
97
100
  if (typeof next === 'function') {
98
101
  return next();
99
102
  }
@@ -154,6 +157,7 @@ export class Adminizer {
154
157
  set: configForms.set ?? defaultForms.set
155
158
  }
156
159
  };
160
+ console.log(this.config);
157
161
  this.modelHandler = new ModelHandler();
158
162
  // TODO: 'hot reload' unbind models & unbind forms
159
163
  await bindModels(this);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "4.2.0-build.66",
4
+ "version": "4.2.0-build.68",
5
5
  "main": "index.js",
6
6
  "exports": {
7
7
  ".": "./index.js",
@@ -17,6 +17,7 @@ export function bindInertia(adminizer) {
17
17
  <script type="module" src="/@vite/client"></script>
18
18
  <script type="module" src="/src/assets/js/app.tsx"></script>
19
19
  <script>window.routePrefix = "${adminizer.config.routePrefix}"</script>
20
+ <script>window.isSails = ${process.env.IS_SAILS ? 'true' : 'false'};</script>
20
21
  `;
21
22
  }
22
23
  else {
@@ -57,11 +58,14 @@ export function bindInertia(adminizer) {
57
58
  });
58
59
  // Route prefix script
59
60
  const routePrefixScript = `<script>window.routePrefix = "${adminizer.config.routePrefix}";</script>`;
61
+ // For Sails JS
62
+ const isSails = `<script>window.isSails = ${process.env.IS_SAILS ? 'true' : 'false'};</script>`;
60
63
  return `
61
64
  ${preloadLinks.join('\n')}
62
65
  ${stylesheets.join('\n')}
63
66
  ${scripts.join('\n')}
64
67
  ${routePrefixScript}
68
+ ${isSails}
65
69
  `;
66
70
  }
67
71
  };
@@ -15,7 +15,8 @@ export default function bindMediaManager(adminizer) {
15
15
  }
16
16
  });
17
17
  // Bind media manager public folder
18
- adminizer.app.use(`/public`, serveStatic(adminizer.config.mediamanager.fileStoragePath));
18
+ if (adminizer.config.bind?.public)
19
+ adminizer.app.use(`/public`, serveStatic(adminizer.config.mediamanager.fileStoragePath));
19
20
  // Bind file icons
20
21
  adminizer.app.use(`${adminizer.config.routePrefix}/fileicons`, serveStatic(path.join(import.meta.dirname, '../fileicons')));
21
22
  }
@@ -134,6 +134,9 @@ let adminpanelConfig = {
134
134
  auth: {
135
135
  enable: false,
136
136
  captcha: true
137
+ },
138
+ bind: {
139
+ public: true
137
140
  }
138
141
  };
139
142
  export function setDefaultConfig(config) {