structured-fw 1.6.0 → 1.7.1

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,8 @@ 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";
8
+ import { Transform } from "node:stream";
7
9
  export class RequestContext {
8
10
  executionStartedAt = null;
9
11
  executionCompletedAt = null;
@@ -69,7 +71,7 @@ export class RequestContext {
69
71
  else if (data === undefined || data === null) {
70
72
  this.sendResponse('', 'text/plain; charset=utf-8');
71
73
  }
72
- else if (data instanceof ReadStream) {
74
+ else if (data instanceof ReadStream || data instanceof Transform) {
73
75
  this.streamingData = true;
74
76
  data.once('end', () => {
75
77
  this.response.end();
@@ -281,7 +283,7 @@ export class RequestContext {
281
283
  }
282
284
  else {
283
285
  let staticAsset = false;
284
- if (this.app.config.url.isAsset(this.request.url || '')) {
286
+ if (this.isAsset()) {
285
287
  const basePath = this.request.url?.startsWith('/assets/ts/') ? './' : '../';
286
288
  const assetPath = path.resolve(basePath + this.request.url);
287
289
  if (existsSync(assetPath)) {
@@ -319,4 +321,15 @@ export class RequestContext {
319
321
  complete() {
320
322
  return this.executionCompletedAt !== null;
321
323
  }
324
+ isAsset() {
325
+ return this.app.config.url.staticAssets.some((pattern) => {
326
+ return minimatch(this.uri, pattern, {
327
+ nonegate: true,
328
+ nobrace: true,
329
+ noext: true,
330
+ nocomment: true,
331
+ partial: false,
332
+ });
333
+ });
334
+ }
322
335
  }
@@ -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.1",
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/*",