structured-fw 1.6.0 → 1.7.0

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/Config.ts CHANGED
@@ -15,11 +15,11 @@ export const config: StructuredConfig = {
15
15
  // setting this to false disallows the use of ClientComponent.redraw and ClientComponent.add
16
16
  componentRender: '/componentRender',
17
17
 
18
- // function that receives the requested URL and returns boolean, if true, treat as static asset
19
- // if there is a registered request handler that matches this same URL, it takes precedence over this
20
- isAsset: function(uri: string) {
21
- return uri.indexOf('/assets/') === 0;
22
- }
18
+ // array of glob patterns that should be treated as static assets
19
+ // make sure to only include files you want to be publicly accessible
20
+ staticAssets: [
21
+ '/assets/**/*'
22
+ ]
23
23
  },
24
24
  routes: {
25
25
  path: '/app/routes'
@@ -40,4 +40,5 @@ export declare class RequestContext<Body extends LooseObject | undefined = Loose
40
40
  isAjax(): boolean;
41
41
  duration(): number;
42
42
  complete(): boolean;
43
+ isAsset(): boolean;
43
44
  }
@@ -4,6 +4,7 @@ import { Document } from "./Document.js";
4
4
  import path from "node:path";
5
5
  import { existsSync, readFileSync, ReadStream } from "node:fs";
6
6
  import { StructuredError } from "../StructuredError.js";
7
+ import { minimatch } from "minimatch";
7
8
  export class RequestContext {
8
9
  executionStartedAt = null;
9
10
  executionCompletedAt = null;
@@ -281,7 +282,7 @@ export class RequestContext {
281
282
  }
282
283
  else {
283
284
  let staticAsset = false;
284
- if (this.app.config.url.isAsset(this.request.url || '')) {
285
+ if (this.isAsset()) {
285
286
  const basePath = this.request.url?.startsWith('/assets/ts/') ? './' : '../';
286
287
  const assetPath = path.resolve(basePath + this.request.url);
287
288
  if (existsSync(assetPath)) {
@@ -319,4 +320,15 @@ export class RequestContext {
319
320
  complete() {
320
321
  return this.executionCompletedAt !== null;
321
322
  }
323
+ isAsset() {
324
+ return this.app.config.url.staticAssets.some((pattern) => {
325
+ return minimatch(this.uri, pattern, {
326
+ nonegate: true,
327
+ nobrace: true,
328
+ noext: true,
329
+ nocomment: true,
330
+ partial: false,
331
+ });
332
+ });
333
+ }
322
334
  }
@@ -4,7 +4,7 @@ export type StructuredConfig = {
4
4
  url: {
5
5
  removeTrailingSlash: boolean;
6
6
  componentRender: false | string;
7
- isAsset: (url: string) => boolean;
7
+ staticAssets: Array<string>;
8
8
  };
9
9
  routes: {
10
10
  readonly path: string;
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "license": "MIT",
20
20
  "type": "module",
21
21
  "main": "build/index",
22
- "version": "1.6.0",
22
+ "version": "1.7.0",
23
23
  "scripts": {
24
24
  "develop": "tsc --watch",
25
25
  "startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,hbs,css index.js",
@@ -37,7 +37,8 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "handlebars": "^4.7.9",
40
- "mime-types": "^3.0.0"
40
+ "mime-types": "^3.0.0",
41
+ "minimatch": "^10.2.5"
41
42
  },
42
43
  "files": [
43
44
  "build/system/*",