@dooboostore/simple-boot-http-server-ssr 1.0.15 → 1.0.17

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.
Files changed (91) hide show
  1. package/README.md +98 -0
  2. package/dist/cjs/SimpleBootHttpSSRServer.js.map +2 -2
  3. package/dist/cjs/bundle-entry.js +46 -14
  4. package/dist/cjs/bundle-entry.js.map +2 -2
  5. package/dist/cjs/filters/SSRDomParserFilter.js +4 -3
  6. package/dist/cjs/filters/SSRDomParserFilter.js.map +2 -2
  7. package/dist/cjs/filters/SSRFilter.js +4 -3
  8. package/dist/cjs/filters/SSRFilter.js.map +2 -2
  9. package/dist/cjs/filters/{SSRLinkDomDomFilter.js → SSRLinkDomFilter.js} +11 -10
  10. package/dist/cjs/filters/SSRLinkDomFilter.js.map +7 -0
  11. package/dist/cjs/filters/SSRSimpleWebComponentDomParserFilter.js +81 -0
  12. package/dist/cjs/filters/SSRSimpleWebComponentDomParserFilter.js.map +7 -0
  13. package/dist/cjs/filters/SSRSimpleWebComponentFilter.js +158 -28
  14. package/dist/cjs/filters/SSRSimpleWebComponentFilter.js.map +2 -2
  15. package/dist/cjs/filters/index.js +9 -3
  16. package/dist/cjs/filters/index.js.map +2 -2
  17. package/dist/cjs/index.js +0 -2
  18. package/dist/cjs/index.js.map +2 -2
  19. package/dist/esm/SimpleBootHttpSSRServer.js.map +2 -2
  20. package/dist/esm/bundle-entry.js +22 -7
  21. package/dist/esm/bundle-entry.js.map +2 -2
  22. package/dist/esm/filters/SSRDomParserFilter.js +5 -4
  23. package/dist/esm/filters/SSRDomParserFilter.js.map +2 -2
  24. package/dist/esm/filters/SSRFilter.js +4 -3
  25. package/dist/esm/filters/SSRFilter.js.map +2 -2
  26. package/dist/esm/filters/{SSRLinkDomDomFilter.js → SSRLinkDomFilter.js} +7 -6
  27. package/dist/esm/filters/SSRLinkDomFilter.js.map +7 -0
  28. package/dist/esm/filters/SSRSimpleWebComponentDomParserFilter.js +58 -0
  29. package/dist/esm/filters/SSRSimpleWebComponentDomParserFilter.js.map +7 -0
  30. package/dist/esm/filters/SSRSimpleWebComponentFilter.js +148 -28
  31. package/dist/esm/filters/SSRSimpleWebComponentFilter.js.map +2 -2
  32. package/dist/esm/filters/index.js +4 -1
  33. package/dist/esm/filters/index.js.map +2 -2
  34. package/dist/esm/index.js +0 -1
  35. package/dist/esm/index.js.map +2 -2
  36. package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js +57949 -20024
  37. package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js.map +4 -4
  38. package/dist/types/SimpleBootHttpSSRServer.d.ts +1 -1
  39. package/dist/types/SimpleBootHttpSSRServer.d.ts.map +1 -1
  40. package/dist/types/bundle-entry.d.ts +11 -7
  41. package/dist/types/bundle-entry.d.ts.map +1 -1
  42. package/dist/types/filters/SSRDomParserFilter.d.ts +3 -3
  43. package/dist/types/filters/SSRDomParserFilter.d.ts.map +1 -1
  44. package/dist/types/filters/SSRFilter.d.ts.map +1 -1
  45. package/dist/types/filters/{SSRLinkDomDomFilter.d.ts → SSRLinkDomFilter.d.ts} +5 -5
  46. package/dist/types/filters/SSRLinkDomFilter.d.ts.map +1 -0
  47. package/dist/types/filters/SSRSimpleWebComponentDomParserFilter.d.ts +37 -0
  48. package/dist/types/filters/SSRSimpleWebComponentDomParserFilter.d.ts.map +1 -0
  49. package/dist/types/filters/SSRSimpleWebComponentFilter.d.ts +23 -3
  50. package/dist/types/filters/SSRSimpleWebComponentFilter.d.ts.map +1 -1
  51. package/dist/types/filters/index.d.ts +4 -1
  52. package/dist/types/filters/index.d.ts.map +1 -1
  53. package/dist/types/index.d.ts +0 -1
  54. package/dist/types/index.d.ts.map +1 -1
  55. package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js +58543 -20621
  56. package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js.map +4 -4
  57. package/package.json +20 -19
  58. package/src/SimpleBootHttpSSRServer.ts +2 -3
  59. package/src/bundle-entry.ts +16 -7
  60. package/src/filters/SSRDomParserFilter.ts +9 -8
  61. package/src/filters/SSRFilter.ts +4 -3
  62. package/src/filters/{SSRLinkDomDomFilter.ts → SSRLinkDomFilter.ts} +7 -6
  63. package/src/filters/SSRSimpleWebComponentDomParserFilter.ts +106 -0
  64. package/src/filters/SSRSimpleWebComponentFilter.ts +242 -39
  65. package/src/filters/index.ts +5 -2
  66. package/src/index.ts +0 -1
  67. package/README.MD +0 -167
  68. package/dist/cjs/decorators/LoadAroundBefore.js +0 -54
  69. package/dist/cjs/decorators/LoadAroundBefore.js.map +0 -7
  70. package/dist/cjs/decorators/SaveAroundAfter.js +0 -53
  71. package/dist/cjs/decorators/SaveAroundAfter.js.map +0 -7
  72. package/dist/cjs/decorators/index.js +0 -24
  73. package/dist/cjs/decorators/index.js.map +0 -7
  74. package/dist/cjs/filters/SSRLinkDomDomFilter.js.map +0 -7
  75. package/dist/esm/decorators/LoadAroundBefore.js +0 -31
  76. package/dist/esm/decorators/LoadAroundBefore.js.map +0 -7
  77. package/dist/esm/decorators/SaveAroundAfter.js +0 -29
  78. package/dist/esm/decorators/SaveAroundAfter.js.map +0 -7
  79. package/dist/esm/decorators/index.js +0 -3
  80. package/dist/esm/decorators/index.js.map +0 -7
  81. package/dist/esm/filters/SSRLinkDomDomFilter.js.map +0 -7
  82. package/dist/types/decorators/LoadAroundBefore.d.ts +0 -2
  83. package/dist/types/decorators/LoadAroundBefore.d.ts.map +0 -1
  84. package/dist/types/decorators/SaveAroundAfter.d.ts +0 -3
  85. package/dist/types/decorators/SaveAroundAfter.d.ts.map +0 -1
  86. package/dist/types/decorators/index.d.ts +0 -3
  87. package/dist/types/decorators/index.d.ts.map +0 -1
  88. package/dist/types/filters/SSRLinkDomDomFilter.d.ts.map +0 -1
  89. package/src/decorators/LoadAroundBefore.ts +0 -28
  90. package/src/decorators/SaveAroundAfter.ts +0 -27
  91. package/src/decorators/index.ts +0 -2
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # @dooboostore/simple-boot-http-server-ssr
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@dooboostore/simple-boot-http-server-ssr.svg?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@dooboostore/simple-boot-http-server-ssr)
4
+ [![Build and Test](https://github.com/dooboostore-develop/packages/actions/workflows/main.yaml/badge.svg?branch=main)](https://github.com/dooboostore-develop/packages/actions/workflows/main.yaml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
6
+
7
+ `@dooboostore/simple-boot-http-server-ssr` provides a powerful **Server-Side Rendering (SSR)** environment by seamlessly integrating `@dooboostore/simple-boot-front` and `@dooboostore/simple-boot-http-server`.
8
+
9
+ By utilizing JSDOM, it creates a virtual DOM environment on the server, executing the same frontend code to deliver fully rendered HTML to users instantly.
10
+
11
+ ---
12
+
13
+ ## 🚀 Key Features
14
+
15
+ - **Seamless SSR**: Render your SPA on the server without code modifications to maximize SEO and First Contentful Paint (FCP).
16
+ - **JSDOM-based Rendering**: Emulate browser APIs in a Node.js environment to execute frontend components.
17
+ - **Component Pooling**: Optimize resource management by pooling SSR instances to handle concurrent requests efficiently.
18
+ - **Automatic Data Hydration**: Serialize server-fetched data into the HTML, preventing redundant API calls during client-side hydration.
19
+ - **Isomorphic Architecture**: Maintain a single codebase for routing, services, and components shared between server and client.
20
+ - **SWC Optimization**: Dedicated filters for `@dooboostore/simple-web-component` to automate component registration and rendering.
21
+
22
+ ---
23
+
24
+ ## 📦 Installation
25
+
26
+ ```bash
27
+ pnpm add @dooboostore/simple-boot-http-server-ssr @dooboostore/simple-web-component jsdom
28
+ ```
29
+
30
+ ---
31
+
32
+ ## 💻 Core Usage
33
+
34
+ ### 1. Universal Bootfactory (bootfactory.ts)
35
+ Define a shared function to initialize the application on both server and client.
36
+
37
+ ```typescript
38
+ export default (window: Window, urlPath?: string) => {
39
+ // Register components
40
+ register(window, [MyComponent, MyPage]);
41
+
42
+ const appElement = window.document.querySelector('#app');
43
+ if (appElement?.connect) {
44
+ const isClient = typeof window !== 'undefined' && window === globalThis.window;
45
+
46
+ appElement.connect({
47
+ rootRouter: RootRouter,
48
+ path: urlPath ?? '/',
49
+ window,
50
+ // Server renders in 'direct' mode, Client hydrates in 'swap' mode
51
+ connectMode: isClient ? 'swap' : 'direct'
52
+ });
53
+ }
54
+ return appElement;
55
+ };
56
+ ```
57
+
58
+ ### 2. Backend Configuration (SSR Filter)
59
+ Add `SSRSimpleWebComponentFilter` to your server configuration to enable SSR.
60
+
61
+ ```typescript
62
+ const swcFilter = new SSRSimpleWebComponentFilter({
63
+ frontDistPath: './dist-client',
64
+ frontDistIndexFileName: 'index.html',
65
+ registerComponents: async (window: any) => {
66
+ // Initialize app in server-side virtual DOM
67
+ bootfactory(window, window.location.pathname);
68
+ }
69
+ });
70
+
71
+ const server = new SimpleBootHttpSSRServer(
72
+ new HttpSSRServerOption({
73
+ filters: [new ResourceFilter('./dist-client'), swcFilter]
74
+ })
75
+ );
76
+ server.run();
77
+ ```
78
+
79
+ ---
80
+
81
+ ## 🌊 Data Hydration
82
+ Automate the process of safely transferring async data from server to client.
83
+
84
+ 1. **Server Side**: Fetches data and embeds it as JSON within the HTML.
85
+ 2. **Client Side**: Detects embedded data on load and restores the initial state.
86
+ 3. **Result**: Provides a fast UI for users while reducing network load.
87
+
88
+ ---
89
+
90
+ ## 📖 Learn More
91
+ Check out the detailed guides and tutorials in the `document` folder.
92
+ - [SSR Basics & JSDOM Usage](https://github.com/dooboostore-develop/packages/tree/main/simple-boot-http-server-ssr/document/Create%20a%20SSR%20Server%20Application%20Framework/02_chapter1_ssr_basics_jsdom.md)
93
+ - [Data Hydration Guide](https://github.com/dooboostore-develop/packages/tree/main/simple-boot-http-server-ssr/document/Create%20a%20SSR%20Server%20Application%20Framework/04_chapter3_data_hydration.md)
94
+
95
+ ---
96
+
97
+ ## License
98
+ [MIT License](LICENSE.md)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/SimpleBootHttpSSRServer.ts"],
4
- "sourcesContent": ["import { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';\n// import { SimstanceManager } from '@dooboostore/simple-boot/simstance/SimstanceManager';\nimport { HttpSSRServerOption } from './option/HttpSSRServerOption';\nimport { ConstructorType } from '@dooboostore/core';\nimport {SimConfig} from \"@dooboostore/simple-boot/decorators/SimDecorator\";\n\nexport class SimpleBootHttpSSRServer extends SimpleBootHttpServer {\n constructor(option?: HttpSSRServerOption) {\n super(option)\n }\n\n run(otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | Symbol, any>) {\n const oi = new Map<ConstructorType<any> | Function | SimConfig | Symbol, any>();\n oi.set(SimpleBootHttpSSRServer, this);\n otherInstanceSim?.forEach((value, key) => oi.set(key, value));\n return super.run(oi);\n }\n\n // TODO: \uB098\uC911\uC5D0 \uBB50\uB77C\uB3C4..\n stop(){\n\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAqC;AAM9B,MAAM,gCAAgC,iDAAqB;AAAA,EAChE,YAAY,QAA8B;AACxC,UAAM,MAAM;AAAA,EACd;AAAA,EAEA,IAAI,kBAAmF;AACrF,UAAM,KAAK,oBAAI,IAA+D;AAC9E,OAAG,IAAI,yBAAyB,IAAI;AACpC,sBAAkB,QAAQ,CAAC,OAAO,QAAQ,GAAG,IAAI,KAAK,KAAK,CAAC;AAC5D,WAAO,MAAM,IAAI,EAAE;AAAA,EACrB;AAAA;AAAA,EAGA,OAAM;AAAA,EAEN;AACF;",
4
+ "sourcesContent": ["import { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';\nimport { HttpSSRServerOption } from './option/HttpSSRServerOption';\nimport { ConstructorType } from '@dooboostore/core';\nimport {SimConfig} from \"@dooboostore/simple-boot/decorators/SimDecorator\";\n\nexport class SimpleBootHttpSSRServer extends SimpleBootHttpServer {\n constructor(option?: HttpSSRServerOption) {\n super(option)\n }\n\n run(otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>) {\n const oi = new Map<ConstructorType<any> | Function | SimConfig | symbol, any>();\n oi.set(SimpleBootHttpSSRServer, this);\n otherInstanceSim?.forEach((value, key) => oi.set(key, value));\n return super.run(oi);\n }\n\n // TODO: \uB098\uC911\uC5D0 \uBB50\uB77C\uB3C4..\n stop(){\n\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAqC;AAK9B,MAAM,gCAAgC,iDAAqB;AAAA,EAChE,YAAY,QAA8B;AACxC,UAAM,MAAM;AAAA,EACd;AAAA,EAEA,IAAI,kBAAmF;AACrF,UAAM,KAAK,oBAAI,IAA+D;AAC9E,OAAG,IAAI,yBAAyB,IAAI;AACpC,sBAAkB,QAAQ,CAAC,OAAO,QAAQ,GAAG,IAAI,KAAK,KAAK,CAAC;AAC5D,WAAO,MAAM,IAAI,EAAE;AAAA,EACrB;AAAA;AAAA,EAGA,OAAM;AAAA,EAEN;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,13 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
5
11
  var __copyProps = (to, from, except, desc) => {
6
12
  if (from && typeof from === "object" || typeof from === "function") {
7
13
  for (let key of __getOwnPropNames(from))
@@ -11,24 +17,50 @@ var __copyProps = (to, from, except, desc) => {
11
17
  return to;
12
18
  };
13
19
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
14
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
29
  var bundle_entry_exports = {};
30
+ __export(bundle_entry_exports, {
31
+ Core: () => Core,
32
+ CoreNode: () => CoreNode,
33
+ CoreWeb: () => CoreWeb,
34
+ DomParser: () => DomParser,
35
+ DomRender: () => DomRender,
36
+ SimpleBoot: () => SimpleBoot,
37
+ SimpleBootFront: () => SimpleBootFront,
38
+ SimpleBootHttpServer: () => SimpleBootHttpServer,
39
+ SimpleWebComponent: () => SimpleWebComponent
40
+ });
16
41
  module.exports = __toCommonJS(bundle_entry_exports);
17
- __reExport(bundle_entry_exports, require("./decorators"), module.exports);
18
- __reExport(bundle_entry_exports, require("./filters"), module.exports);
19
- __reExport(bundle_entry_exports, require("./initializers"), module.exports);
20
- __reExport(bundle_entry_exports, require("./option"), module.exports);
21
- __reExport(bundle_entry_exports, require("./proxy"), module.exports);
22
- __reExport(bundle_entry_exports, require("./SimpleBootHttpSSRFactory"), module.exports);
23
- __reExport(bundle_entry_exports, require("./SimpleBootHttpSSRServer"), module.exports);
42
+ var import_reflect_metadata = require("reflect-metadata");
43
+ __reExport(bundle_entry_exports, require("./index"), module.exports);
44
+ var Core = __toESM(require("@dooboostore/core"), 1);
45
+ var CoreNode = __toESM(require("@dooboostore/core-node"), 1);
46
+ var CoreWeb = __toESM(require("@dooboostore/core-web"), 1);
47
+ var DomParser = __toESM(require("@dooboostore/dom-parser"), 1);
48
+ var DomRender = __toESM(require("@dooboostore/dom-render"), 1);
49
+ var SimpleBoot = __toESM(require("@dooboostore/simple-boot"), 1);
50
+ var SimpleBootFront = __toESM(require("@dooboostore/simple-boot-front"), 1);
51
+ var SimpleBootHttpServer = __toESM(require("@dooboostore/simple-boot-http-server"), 1);
52
+ var SimpleWebComponent = __toESM(require("@dooboostore/simple-web-component"), 1);
24
53
  // Annotate the CommonJS export names for ESM import in node:
25
54
  0 && (module.exports = {
26
- ...require("./decorators"),
27
- ...require("./filters"),
28
- ...require("./initializers"),
29
- ...require("./option"),
30
- ...require("./proxy"),
31
- ...require("./SimpleBootHttpSSRFactory"),
32
- ...require("./SimpleBootHttpSSRServer")
55
+ Core,
56
+ CoreNode,
57
+ CoreWeb,
58
+ DomParser,
59
+ DomRender,
60
+ SimpleBoot,
61
+ SimpleBootFront,
62
+ SimpleBootHttpServer,
63
+ SimpleWebComponent,
64
+ ...require("./index")
33
65
  });
34
66
  //# sourceMappingURL=bundle-entry.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/bundle-entry.ts"],
4
- "sourcesContent": ["export * from './decorators';\nexport * from './filters';\nexport * from './initializers';\nexport * from './option';\nexport * from './proxy';\nexport * from './SimpleBootHttpSSRFactory';\nexport * from './SimpleBootHttpSSRServer';"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,iCAAc,yBAAd;AACA,iCAAc,sBADd;AAEA,iCAAc,2BAFd;AAGA,iCAAc,qBAHd;AAIA,iCAAc,oBAJd;AAKA,iCAAc,uCALd;AAMA,iCAAc,sCANd;",
4
+ "sourcesContent": ["import 'reflect-metadata';\n\n// simple-boot-http-server-ssr itself\nexport * from './index';\n\n// Re-export peer dependencies so bundle consumers can access them\n// without separately importing each package\nexport * as Core from '@dooboostore/core';\nexport * as CoreNode from '@dooboostore/core-node';\nexport * as CoreWeb from '@dooboostore/core-web';\nexport * as DomParser from '@dooboostore/dom-parser';\nexport * as DomRender from '@dooboostore/dom-render';\nexport * as SimpleBoot from '@dooboostore/simple-boot';\nexport * as SimpleBootFront from '@dooboostore/simple-boot-front';\nexport * as SimpleBootHttpServer from '@dooboostore/simple-boot-http-server';\nexport * as SimpleWebComponent from '@dooboostore/simple-web-component';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AAGP,iCAAc,oBAHd;AAOA,WAAsB;AACtB,eAA0B;AAC1B,cAAyB;AACzB,gBAA2B;AAC3B,gBAA2B;AAC3B,iBAA4B;AAC5B,sBAAiC;AACjC,2BAAsC;AACtC,yBAAoC;",
6
6
  "names": []
7
7
  }
@@ -23,6 +23,7 @@ module.exports = __toCommonJS(SSRDomParserFilter_exports);
23
23
  var import_RequestResponse = require("@dooboostore/simple-boot-http-server/models/RequestResponse");
24
24
  var import_HttpHeaders = require("@dooboostore/simple-boot-http-server/codes/HttpHeaders");
25
25
  var import_core = require("@dooboostore/core");
26
+ var import_operators = require("@dooboostore/core/message/operators");
26
27
  var import_Mimes = require("@dooboostore/simple-boot-http-server/codes/Mimes");
27
28
  var import_HttpStatus = require("@dooboostore/simple-boot-http-server/codes/HttpStatus");
28
29
  var import_NotFoundError = require("@dooboostore/simple-boot-http-server/errors/NotFoundError");
@@ -90,14 +91,14 @@ class SSRDomParserFilter {
90
91
  throw new import_NotFoundError.NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });
91
92
  }
92
93
  }
93
- const data = await import_core.MessageInternal.firstValueFrom(
94
+ const data = await (0, import_core.firstValueFrom)(
94
95
  simpleBootFront.routingObservable.pipe(
95
- import_core.MessageOperator.filter((it) => {
96
+ (0, import_operators.filter)((it) => {
96
97
  const sw = it.triggerPoint === "end" && typeof it.routerModule.intent.uri === "string" && targetUrl.endsWith(it.routerModule.intent.uri);
97
98
  return sw;
98
99
  }),
99
100
  // delay(1000),
100
- import_core.MessageOperator.first()
101
+ (0, import_operators.first)()
101
102
  )
102
103
  );
103
104
  simpleBootFront.writeDataHydration();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/filters/SSRDomParserFilter.ts"],
4
- "sourcesContent": ["import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';\nimport { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';\nimport { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';\nimport { ConstructorType, AsyncBlockingQueue, RandomUtils, MessageOperator, MessageInternal, Promises } from '@dooboostore/core';\nimport { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';\nimport { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';\nimport { HttpStatus } from '@dooboostore/simple-boot-http-server/codes/HttpStatus';\nimport { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';\nimport { SimFrontOption } from '@dooboostore/simple-boot-front/option/SimFrontOption';\nimport { SimpleBootFront } from '@dooboostore/simple-boot-front/SimpleBootFront';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render';\nimport { parseHTML } from 'linkedom';\nimport { DomParserInitializer } from '../initializers/DomParserInitializer';\nimport { JsdomInitializer } from '../initializers';\nimport { SimConfig } from '@dooboostore/simple-boot/decorators/SimDecorator';\n\nexport type FactoryAndParams = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n factorySimFrontOption: (window: any) => SimFrontOption;\n factory: SimpleBootHttpSSRFactory;\n // poolOption: {\n // max: number;\n // min: number;\n // clearIntervalTime?: number;\n // };\n using: ConstructorType<any>[];\n domExcludes?: ConstructorType<any>[];\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n simpleBootFront?: {\n notFoundError?: boolean;\n };\n};\n\nexport class SSRDomParserFilter implements Filter {\n // private simpleBootFrontPool: SimpleBootFront[] = [];\n // private simpleBootFrontQueue = new AsyncBlockingQueue<SimpleBootFront>();\n // private indexHTML: string;\n private welcomUrl = 'http://localhost';\n // private poolGeneration = 0;\n // private intervalId?: NodeJS.Timeout;\n\n constructor(\n public config: FactoryAndParams,\n public otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | Symbol, any>\n ) {\n config.frontDistIndexFileName = config.frontDistIndexFileName || 'index.html';\n // this.indexHTML = JsdomInitializer.loadFile(this.config.frontDistPath, config.frontDistIndexFileName);\n }\n\n async onInit(app: SimpleBootHttpServer) {\n // for (let i = 0; i < this.config.poolOption.min; i++) {\n // await this.pushQueue();\n // }\n // if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {\n // this.intervalId = setInterval(() => {\n // this.poolGeneration++;\n // }, this.config.poolOption.clearIntervalTime);\n // }\n }\n\n async onDestroy() {\n // if (this.intervalId) {\n // clearInterval(this.intervalId);\n // }\n // // this.simpleBootFrontQueue.clear();\n // this.simpleBootFrontPool.forEach(front => {\n // // JSDOM\uB3C4 \uC815\uB9AC (\uD558\uC704 \uD638\uD658\uC131)\n // (front as any).jsdom?.window.close();\n // // Window close - \uC774\uAC83\uB9CC\uC73C\uB85C WindowBase.close()\uAC00 \uD638\uCD9C\uB418\uC5B4 \uBA54\uBAA8\uB9AC \uC815\uB9AC\uB428\n // (front.option.window as any)?.close?.();\n // });\n // this.simpleBootFrontPool = [];\n }\n\n async makePage(url = this.welcomUrl) {\n const domParserInitializer = new DomParserInitializer(this.config.frontDistPath, this.config.frontDistIndexFileName || 'index.html', { url: url });\n const window = await domParserInitializer.run();\n // window.document.querySelector('#app').setAttribute(('vvv'),'zzz')\n // console.log('vvv', window.document.querySelector('#app'))\n // console.log('------', window.document.documentElement.outerHTML);\n return { window, domParserInitializer };\n // const jsdom = await new JsdomInitializer(\n // this.config.frontDistPath,\n // this.config.frontDistIndexFileName || 'index.html',\n // { url: this.welcomUrl }\n // ).run();\n // return { window: jsdom.window as any, domParserInitializer: {destroy: () => {jsdom.window.close()}} };\n // return jsdom;\n }\n\n async makeFront(window: Window, otherInstanceSim?: Map<Function | ConstructorType<any> | SimConfig | Symbol, any>) {\n const name = RandomUtils.uuid();\n (window as any).ssrUse = false;\n const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));\n const domExcludes = [RequestResponse, ...(this.config.domExcludes || [])];\n const simpleBootFront = await this.config.factory.create(option, this.config.using, domExcludes);\n otherInstanceSim ??= new Map<Function | ConstructorType<any> | SimConfig | Symbol, any>();\n this.otherInstanceSim?.forEach((v, k) => otherInstanceSim!.set(k, v));\n\n simpleBootFront.run(otherInstanceSim);\n // (simpleBootFront as any).generation = this.poolGeneration;\n return simpleBootFront;\n }\n\n // enqueueFrontApp(simpleBootFront: SimpleBootFront) {\n // // this.simpleBootFrontPool.set(simpleBootFront.option.name!, simpleBootFront);\n // this.simpleBootFrontPool.push(simpleBootFront);\n // this.simpleBootFrontQueue.enqueue(simpleBootFront);\n // }\n //\n // async pushQueue() {\n // if (this.simpleBootFrontPool.length < this.config.poolOption.max) {\n // this.enqueueFrontApp(await this.makeFront(await this.makePage()));\n // }\n // }\n\n async proceedBefore({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return false;\n }\n if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {\n // if (this.simpleBootFrontQueue.isEmpty()) {\n // await this.pushQueue();\n // }\n // const simpleBootFront = await this.simpleBootFrontQueue.dequeue();\n const url = rr.reqUrlObj({ host: 'localhost' });\n const targetUrl = url.toString() ?? this.welcomUrl;\n const { window, domParserInitializer } = await this.makePage(targetUrl);\n const otherSim = new Map<Function | ConstructorType<any> | SimConfig | Symbol, any>();\n otherSim.set(RequestResponse, rr);\n const simpleBootFront = await this.makeFront(window, otherSim);\n try {\n (simpleBootFront.option.window as any).ssrUse = true;\n // console.log(simpleBootFront.routing)\n if (this.config.simpleBootFront?.notFoundError) {\n // intent router check first\n const intent = await simpleBootFront.routingRouterModule(url.pathname);\n // route\uB97C \uBABB\uCC3E\uC740\uC0C1\uD0DC\uC5D0\uC11C router path\uAE4C\uC9C0 \uC548\uB9DE\uC73C\uBA74 404 \uCC98\uB9AC\uD55C\uB2E4. route\uB791 router\uB791 \uB2E4\uB974\uB2C8\uAE50 \uD5DB\uAC08\uB9AC\uC9C0\uB9D0\uB3C4\uB85D\n if (intent.module === undefined && !intent.getRouterPathData(rr.reqUrlPathName)) {\n throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });\n }\n }\n\n const data = await MessageInternal.firstValueFrom(\n simpleBootFront.routingObservable.pipe(\n MessageOperator.filter(it => {\n\n const sw = it.triggerPoint === 'end' && typeof it.routerModule.intent.uri === 'string' && targetUrl.endsWith(it.routerModule.intent.uri);\n return sw;\n }),\n // delay(1000),\n MessageOperator.first()\n )\n );\n\n // [\uC544\uD0A4\uD14D\uD2B8\uB2D8\uC758 \uC815\uC11D] \uD558\uC774\uB4DC\uB808\uC774\uC158 \uB370\uC774\uD130\uB97C \uAC00\uC0C1 \uC708\uB3C4\uC6B0\uC758 body\uC5D0 script \uD0DC\uADF8\uB85C \uBC15\uC81C\n // @ts-ignore: writeDataHydration is part of the \uC815\uC11D\n simpleBootFront.writeDataHydration();\n simpleBootFront.clearDataHydration();\n\n const html = this.makeHTML(simpleBootFront);\n await this.writeOkHtmlAndEnd({ rr }, html);\n } finally {\n try {\n (simpleBootFront.option.window as any).ssrUse = false;\n window.close();\n simpleBootFront.onDestroy();\n\n // window.close()\uB9CC \uD638\uCD9C\uD558\uBA74 WindowBase.close()\uAC00 \uC2E4\uD589\uB418\uC5B4 \uBA54\uBAA8\uB9AC \uC815\uB9AC\uB428\n (simpleBootFront.option.window as any)?.close?.();\n domParserInitializer.destroy();\n } catch (e) {\n console.log('eeeeee', e);\n }\n\n // const index = this.simpleBootPool.indexOf(simpleBootFront);\n // if (index > -1) {\n // this.simpleBootPool.splice(index, 1);\n // }\n // this.pushQueue();\n }\n return false;\n } else {\n return true;\n }\n }\n\n makeHTML(simpleBootFront: SimpleBootFront) {\n (simpleBootFront.option.window as any).document.querySelectorAll('*').forEach((el: HTMLElement) => {\n Array.from(el.attributes).forEach(attr => {\n if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {\n el.removeAttribute(attr.name);\n }\n });\n });\n let html = simpleBootFront.option.window.document.documentElement.outerHTML;\n if (!/^<!DOCTYPE html>/i.test(html)) {\n html = '<!DOCTYPE html>' + html;\n }\n html = html.replace(/\\$\\{[\\s\\S]*?\\}\\$/g, '');\n\n // [\uC544\uD0A4\uD14D\uD2B8\uB2D8\uC758 \uC815\uC11D]\n // body\uC5D0 \uC9C1\uC811 append\uB41C script tag\uAC00 outerHTML\uC5D0 \uC774\uBBF8 \uD3EC\uD568\uB418\uC5B4 \uC788\uC73C\uBBC0\uB85C \uCD94\uAC00 \uC870\uC791\uC740 \uBD88\uD544\uC694\uD569\uB2C8\uB2E4.\n\n return html;\n }\n\n async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }: { rr: RequestResponse; status?: HttpStatus }, html: string) {\n rr.resStatusCode(status);\n rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);\n await rr.resEnd(html);\n }\n\n async proceedAfter({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n return true;\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAgC;AAChC,yBAA4B;AAE5B,kBAA6G;AAE7G,mBAAsB;AACtB,wBAA2B;AAK3B,2BAA8B;AAC9B,wBAA+B;AAE/B,kCAAqC;AAsB9B,MAAM,mBAAqC;AAAA;AAAA;AAAA,EAQhD,YACS,QACA,kBACP;AAFO;AACA;AANT;AAAA;AAAA;AAAA,S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C,IAAC,gBAAgB,OAAO,OAAe,SAAS,iBAAiB,GAAG,EAAE,QAAQ,CAAC,OAAoB;AACjG,YAAM,KAAK,GAAG,UAAU,EAAE,QAAQ,UAAQ;AACxC,YAAI,OAAO,KAAK,KAAK,IAAI,KAAK,YAAY,KAAK,KAAK,IAAI,KAAK,YAAY,KAAK,KAAK,IAAI,GAAG;AACxF,aAAG,gBAAgB,KAAK,IAAI;AAAA,QAC9B;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AACD,QAAI,OAAO,gBAAgB,OAAO,OAAO,SAAS,gBAAgB;AAClE,QAAI,CAAC,oBAAoB,KAAK,IAAI,GAAG;AACnC,aAAO,oBAAoB;AAAA,IAC7B;AACA,WAAO,KAAK,QAAQ,qBAAqB,EAAE;AAK3C,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,kBAAkB,EAAE,IAAI,SAAS,6BAAW,GAAG,GAAiD,MAAc;AAClH,OAAG,cAAc,MAAM;AACvB,OAAG,aAAa,+BAAY,aAAa,mBAAM,QAAQ;AACvD,UAAM,GAAG,OAAO,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,aAAa,EAAE,IAAI,IAAI,GAAkF;AAC7G,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';\nimport { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';\nimport { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';\nimport { ConstructorType, AsyncBlockingQueue, RandomUtils, firstValueFrom } from '@dooboostore/core';\nimport { filter, first } from '@dooboostore/core/message/operators';\nimport { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';\nimport { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';\nimport { HttpStatus } from '@dooboostore/simple-boot-http-server/codes/HttpStatus';\nimport { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';\nimport { SimFrontOption } from '@dooboostore/simple-boot-front/option/SimFrontOption';\nimport { SimpleBootFront } from '@dooboostore/simple-boot-front/SimpleBootFront';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render';\nimport { parseHTML } from 'linkedom';\nimport { DomParserInitializer } from '../initializers/DomParserInitializer';\nimport { JsdomInitializer } from '../initializers';\nimport { SimConfig } from '@dooboostore/simple-boot/decorators/SimDecorator';\n\nexport type DomParserFactoryAndParams = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n factorySimFrontOption: (window: any) => SimFrontOption;\n factory: SimpleBootHttpSSRFactory;\n // poolOption: {\n // max: number;\n // min: number;\n // clearIntervalTime?: number;\n // };\n using: ConstructorType<any>[];\n domExcludes?: ConstructorType<any>[];\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n simpleBootFront?: {\n notFoundError?: boolean;\n };\n};\n\nexport class SSRDomParserFilter implements Filter {\n // private simpleBootFrontPool: SimpleBootFront[] = [];\n // private simpleBootFrontQueue = new AsyncBlockingQueue<SimpleBootFront>();\n // private indexHTML: string;\n private welcomUrl = 'http://localhost';\n // private poolGeneration = 0;\n // private intervalId?: NodeJS.Timeout;\n\n constructor(\n public config: DomParserFactoryAndParams,\n public otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | Symbol, any>\n ) {\n config.frontDistIndexFileName = config.frontDistIndexFileName || 'index.html';\n // this.indexHTML = JsdomInitializer.loadFile(this.config.frontDistPath, config.frontDistIndexFileName);\n }\n\n async onInit(app: SimpleBootHttpServer) {\n // for (let i = 0; i < this.config.poolOption.min; i++) {\n // await this.pushQueue();\n // }\n // if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {\n // this.intervalId = setInterval(() => {\n // this.poolGeneration++;\n // }, this.config.poolOption.clearIntervalTime);\n // }\n }\n\n async onDestroy() {\n // if (this.intervalId) {\n // clearInterval(this.intervalId);\n // }\n // // this.simpleBootFrontQueue.clear();\n // this.simpleBootFrontPool.forEach(front => {\n // // JSDOM\uB3C4 \uC815\uB9AC (\uD558\uC704 \uD638\uD658\uC131)\n // (front as any).jsdom?.window.close();\n // // Window close - \uC774\uAC83\uB9CC\uC73C\uB85C WindowBase.close()\uAC00 \uD638\uCD9C\uB418\uC5B4 \uBA54\uBAA8\uB9AC \uC815\uB9AC\uB428\n // (front.option.window as any)?.close?.();\n // });\n // this.simpleBootFrontPool = [];\n }\n\n async makePage(url = this.welcomUrl) {\n const domParserInitializer = new DomParserInitializer(this.config.frontDistPath, this.config.frontDistIndexFileName || 'index.html', { url: url });\n const window = await domParserInitializer.run();\n // window.document.querySelector('#app').setAttribute(('vvv'),'zzz')\n // console.log('vvv', window.document.querySelector('#app'))\n // console.log('------', window.document.documentElement.outerHTML);\n return { window, domParserInitializer };\n // const jsdom = await new JsdomInitializer(\n // this.config.frontDistPath,\n // this.config.frontDistIndexFileName || 'index.html',\n // { url: this.welcomUrl }\n // ).run();\n // return { window: jsdom.window as any, domParserInitializer: {destroy: () => {jsdom.window.close()}} };\n // return jsdom;\n }\n\n async makeFront(window: Window, otherInstanceSim?: Map<Function | ConstructorType<any> | SimConfig | Symbol, any>) {\n const name = RandomUtils.uuid();\n (window as any).ssrUse = false;\n const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));\n const domExcludes = [RequestResponse, ...(this.config.domExcludes || [])];\n const simpleBootFront = await this.config.factory.create(option, this.config.using, domExcludes);\n otherInstanceSim ??= new Map<Function | ConstructorType<any> | SimConfig | symbol, any>();\n this.otherInstanceSim?.forEach((v, k) => otherInstanceSim!.set(k, v));\n\n simpleBootFront.run(otherInstanceSim as any);\n // (simpleBootFront as any).generation = this.poolGeneration;\n return simpleBootFront;\n }\n\n // enqueueFrontApp(simpleBootFront: SimpleBootFront) {\n // // this.simpleBootFrontPool.set(simpleBootFront.option.name!, simpleBootFront);\n // this.simpleBootFrontPool.push(simpleBootFront);\n // this.simpleBootFrontQueue.enqueue(simpleBootFront);\n // }\n //\n // async pushQueue() {\n // if (this.simpleBootFrontPool.length < this.config.poolOption.max) {\n // this.enqueueFrontApp(await this.makeFront(await this.makePage()));\n // }\n // }\n\n async proceedBefore({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return false;\n }\n if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {\n // if (this.simpleBootFrontQueue.isEmpty()) {\n // await this.pushQueue();\n // }\n // const simpleBootFront = await this.simpleBootFrontQueue.dequeue();\n const url = rr.reqUrlObj({ host: 'localhost' });\n const targetUrl = url.toString() ?? this.welcomUrl;\n const { window, domParserInitializer } = await this.makePage(targetUrl);\n const otherSim = new Map<Function | ConstructorType<any> | SimConfig | Symbol, any>();\n otherSim.set(RequestResponse, rr);\n const simpleBootFront = await this.makeFront(window, otherSim);\n try {\n (simpleBootFront.option.window as any).ssrUse = true;\n // console.log(simpleBootFront.routing)\n if (this.config.simpleBootFront?.notFoundError) {\n // intent router check first\n const intent = await simpleBootFront.routingRouterModule(url.pathname);\n // route\uB97C \uBABB\uCC3E\uC740\uC0C1\uD0DC\uC5D0\uC11C router path\uAE4C\uC9C0 \uC548\uB9DE\uC73C\uBA74 404 \uCC98\uB9AC\uD55C\uB2E4. route\uB791 router\uB791 \uB2E4\uB974\uB2C8\uAE50 \uD5DB\uAC08\uB9AC\uC9C0\uB9D0\uB3C4\uB85D\n if (intent.module === undefined && !intent.getRouterPathData(rr.reqUrlPathName)) {\n throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });\n }\n }\n\n const data = await firstValueFrom(\n simpleBootFront.routingObservable.pipe(\n filter(it => {\n\n const sw = it.triggerPoint === 'end' && typeof it.routerModule.intent.uri === 'string' && targetUrl.endsWith(it.routerModule.intent.uri);\n return sw;\n }),\n // delay(1000),\n first()\n )\n );\n\n // [\uC544\uD0A4\uD14D\uD2B8\uB2D8\uC758 \uC815\uC11D] \uD558\uC774\uB4DC\uB808\uC774\uC158 \uB370\uC774\uD130\uB97C \uAC00\uC0C1 \uC708\uB3C4\uC6B0\uC758 body\uC5D0 script \uD0DC\uADF8\uB85C \uBC15\uC81C\n // @ts-ignore: writeDataHydration is part of the \uC815\uC11D\n simpleBootFront.writeDataHydration();\n simpleBootFront.clearDataHydration();\n\n const html = this.makeHTML(simpleBootFront);\n await this.writeOkHtmlAndEnd({ rr }, html);\n } finally {\n try {\n (simpleBootFront.option.window as any).ssrUse = false;\n window.close();\n simpleBootFront.onDestroy();\n\n // window.close()\uB9CC \uD638\uCD9C\uD558\uBA74 WindowBase.close()\uAC00 \uC2E4\uD589\uB418\uC5B4 \uBA54\uBAA8\uB9AC \uC815\uB9AC\uB428\n (simpleBootFront.option.window as any)?.close?.();\n domParserInitializer.destroy();\n } catch (e) {\n console.log('eeeeee', e);\n }\n\n // const index = this.simpleBootPool.indexOf(simpleBootFront);\n // if (index > -1) {\n // this.simpleBootPool.splice(index, 1);\n // }\n // this.pushQueue();\n }\n return false;\n } else {\n return true;\n }\n }\n\n makeHTML(simpleBootFront: SimpleBootFront) {\n (simpleBootFront.option.window as any).document.querySelectorAll('*').forEach((el: HTMLElement) => {\n Array.from(el.attributes).forEach(attr => {\n if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {\n el.removeAttribute(attr.name);\n }\n });\n });\n let html = simpleBootFront.option.window.document.documentElement.outerHTML;\n if (!/^<!DOCTYPE html>/i.test(html)) {\n html = '<!DOCTYPE html>' + html;\n }\n html = html.replace(/\\$\\{[\\s\\S]*?\\}\\$/g, '');\n\n // [\uC544\uD0A4\uD14D\uD2B8\uB2D8\uC758 \uC815\uC11D]\n // body\uC5D0 \uC9C1\uC811 append\uB41C script tag\uAC00 outerHTML\uC5D0 \uC774\uBBF8 \uD3EC\uD568\uB418\uC5B4 \uC788\uC73C\uBBC0\uB85C \uCD94\uAC00 \uC870\uC791\uC740 \uBD88\uD544\uC694\uD569\uB2C8\uB2E4.\n\n return html;\n }\n\n async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }: { rr: RequestResponse; status?: HttpStatus }, html: string) {\n rr.resStatusCode(status);\n rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);\n await rr.resEnd(html);\n }\n\n async proceedAfter({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n return true;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAgC;AAChC,yBAA4B;AAE5B,kBAAiF;AACjF,uBAA8B;AAE9B,mBAAsB;AACtB,wBAA2B;AAK3B,2BAA8B;AAC9B,wBAA+B;AAE/B,kCAAqC;AAsB9B,MAAM,mBAAqC;AAAA;AAAA;AAAA,EAQhD,YACS,QACA,kBACP;AAFO;AACA;AANT;AAAA;AAAA;AAAA,SAAQ,YAAY;AAQlB,WAAO,yBAAyB,OAAO,0BAA0B;AAAA,EAEnE;AAAA,EAEA,MAAM,OAAO,KAA2B;AAAA,EASxC;AAAA,EAEA,MAAM,YAAY;AAAA,EAYlB;AAAA,EAEA,MAAM,SAAS,MAAM,KAAK,WAAW;AACnC,UAAM,uBAAuB,IAAI,iDAAqB,KAAK,OAAO,eAAe,KAAK,OAAO,0BAA0B,cAAc,EAAE,IAAS,CAAC;AACjJ,UAAM,SAAS,MAAM,qBAAqB,IAAI;AAI9C,WAAO,EAAE,QAAQ,qBAAqB;AAAA,EAQxC;AAAA,EAEA,MAAM,UAAU,QAAgB,kBAAmF;AACjH,UAAM,OAAO,wBAAY,KAAK;AAC9B,IAAC,OAAe,SAAS;AACzB,UAAM,SAAS,KAAK,OAAO,sBAAsB,iCAAe,MAAM,MAAM,CAAC;AAC7E,UAAM,cAAc,CAAC,wCAAiB,GAAI,KAAK,OAAO,eAAe,CAAC,CAAE;AACxE,UAAM,kBAAkB,MAAM,K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AM,GAAG,OAAO,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,aAAa,EAAE,IAAI,IAAI,GAAkF;AAC7G,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
@@ -22,6 +22,7 @@ __export(SSRFilter_exports, {
22
22
  module.exports = __toCommonJS(SSRFilter_exports);
23
23
  var import_HttpHeaders = require("@dooboostore/simple-boot-http-server/codes/HttpHeaders");
24
24
  var import_core = require("@dooboostore/core");
25
+ var import_operators = require("@dooboostore/core/message/operators");
25
26
  var import_JsdomInitializer = require("../initializers/JsdomInitializer");
26
27
  var import_Mimes = require("@dooboostore/simple-boot-http-server/codes/Mimes");
27
28
  var import_HttpStatus = require("@dooboostore/simple-boot-http-server/codes/HttpStatus");
@@ -119,15 +120,15 @@ class SSRFilter {
119
120
  const targetUrl = url.toString();
120
121
  await simpleBootFront.goRouting(targetUrl);
121
122
  await new Promise((r) => setTimeout(r, 0));
122
- const data = await import_core.MessageInternal.firstValueFrom(
123
+ const data = await (0, import_core.firstValueFrom)(
123
124
  // @ts-ignore
124
125
  simpleBootFront.routingObservable.pipe(
125
126
  // @ts-ignore
126
- import_core.MessageOperator.filter(
127
+ MessageOperator.filter(
127
128
  (it) => it.triggerPoint === "end" && typeof it.routerModule.intent.uri === "string" && targetUrl.endsWith(it.routerModule.intent.uri)
128
129
  ),
129
130
  // delay(1000),
130
- import_core.MessageOperator.first()
131
+ (0, import_operators.first)()
131
132
  )
132
133
  );
133
134
  const html = this.makeHTML(simpleBootFront);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/filters/SSRFilter.ts"],
4
- "sourcesContent": ["import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';\nimport { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';\nimport { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';\nimport { ConstructorType, AsyncBlockingQueue, RandomUtils, MessageOperator, MessageInternal } from '@dooboostore/core';\nimport { JsdomInitializer } from '../initializers/JsdomInitializer';\nimport { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';\nimport { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';\nimport { HttpStatus } from '@dooboostore/simple-boot-http-server/codes/HttpStatus';\nimport { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';\nimport { SimFrontOption } from '@dooboostore/simple-boot-front/option/SimFrontOption';\nimport { SimpleBootFront } from '@dooboostore/simple-boot-front/SimpleBootFront';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render';\n\nexport type FactoryAndParams = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n factorySimFrontOption: (window: any) => SimFrontOption;\n factory: SimpleBootHttpSSRFactory;\n poolOption: {\n max: number;\n min: number;\n clearIntervalTime?: number;\n };\n using: ConstructorType<any>[];\n domExcludes?: ConstructorType<any>[];\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n simpleBootFront?: {\n notFoundError?: boolean;\n };\n};\n\nexport class SSRFilter implements Filter {\n private simpleBootFrontPool: SimpleBootFront[] = [];\n private simpleBootFrontQueue = new AsyncBlockingQueue<SimpleBootFront>();\n private indexHTML: string;\n private welcomUrl = 'http://localhost';\n private poolGeneration = 0;\n private intervalId?: NodeJS.Timeout;\n\n constructor(\n public config: FactoryAndParams,\n public otherInstanceSim?: Map<ConstructorType<any>, any>\n ) {\n config.frontDistIndexFileName = config.frontDistIndexFileName || 'index.html';\n this.indexHTML = JsdomInitializer.loadFile(this.config.frontDistPath, config.frontDistIndexFileName);\n }\n\n async onInit(app: SimpleBootHttpServer) {\n for (let i = 0; i < this.config.poolOption.min; i++) {\n await this.pushQueue();\n }\n\n if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {\n this.intervalId = setInterval(() => {\n this.poolGeneration++;\n }, this.config.poolOption.clearIntervalTime);\n }\n // console.log('SimpleBootHttpSSRFactory init success ', + this.simpleBootFrontPool.length)\n }\n\n async onDestroy() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n // this.simpleBootFrontQueue.clear();\n this.simpleBootFrontPool.forEach(front => {\n (front as any).jsdom?.window.close();\n });\n this.simpleBootFrontPool = [];\n }\n\n // workerTs(workerOptions: WorkerOptions) {\n // workerOptions.eval = true;\n // if (!workerOptions.workerData) {\n // workerOptions.workerData = {};\n // }\n // workerOptions.workerData.__filename = '/Users/hyunhakim/source/visualkhh/pet-space/libs/simple-boot-http-ssr/dist/filters/SSRCreatorWorker.js';\n // return new Worker(` const wk = require('worker_threads'); require('ts-node').register(); let file = wk.workerData.__filename; require(file); `, workerOptions,);\n // }\n\n async makeJsdom() {\n const jsdom = await new JsdomInitializer(\n this.config.frontDistPath,\n this.config.frontDistIndexFileName || 'index.html',\n { url: this.welcomUrl }\n ).run();\n return jsdom;\n }\n\n async makeFront(jsdom: JSDOM.JSDOM) {\n const name = RandomUtils.uuid();\n // const jsdom = await this.makeJsdom();\n const window = jsdom.window as unknown as Window & typeof globalThis;\n (window as any).ssrUse = false;\n const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));\n const simpleBootFront = await this.config.factory.create(option, this.config.using, this.config.domExcludes);\n simpleBootFront.run(this.otherInstanceSim);\n (simpleBootFront as any).jsdom = jsdom;\n (simpleBootFront as any).generation = this.poolGeneration;\n return simpleBootFront;\n }\n\n enqueueFrontApp(simpleBootFront: SimpleBootFront) {\n // this.simpleBootFrontPool.set(simpleBootFront.option.name!, simpleBootFront);\n this.simpleBootFrontPool.push(simpleBootFront);\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n\n // async pushQueue(destorFront?: SimpleBootFront) {\n // if (destorFront) {\n // this.simpleBootFrontPool.delete(destorFront.option.name!);\n // }\n async pushQueue() {\n if (this.simpleBootFrontPool.length < this.config.poolOption.max) {\n this.enqueueFrontApp(await this.makeFront(await this.makeJsdom()));\n }\n }\n\n async proceedBefore({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return false;\n }\n if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {\n if (this.simpleBootFrontQueue.isEmpty()) {\n await this.pushQueue();\n }\n const simpleBootFront = await this.simpleBootFrontQueue.dequeue();\n try {\n // console.log('SSRFilter before-->' , simpleBootFront.option.name, 'poolLength:',this.simpleBootFrontPool.size);\n (simpleBootFront.option.window as any).ssrUse = true;\n delete (simpleBootFront.option.window as any).server_side_data;\n\n const url = rr.reqUrlObj({ host: 'localhost' });\n if (this.config.simpleBootFront?.notFoundError) {\n // intent router check first\n const intent = await simpleBootFront.routingRouterModule(url.pathname);\n // route\uB97C \uBABB\uCC3E\uC740\uC0C1\uD0DC\uC5D0\uC11C router path\uAE4C\uC9C0 \uC548\uB9DE\uC73C\uBA74 404 \uCC98\uB9AC\uD55C\uB2E4. route\uB791 router\uB791 \uB2E4\uB974\uB2C8\uAE50 \uD5DB\uAC08\uB9AC\uC9C0\uB9D0\uB3C4\uB85D\n if (intent.module === undefined && !intent.getRouterPathData(rr.reqUrlPathName)) {\n throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });\n }\n }\n\n // runRouting!!\n const targetUrl = url.toString();\n // console.log('rrrrr');\n // simpleBootFront.routingSubjectObservable.subscribe(it => {\n // if (it.state === 'end' && it.routerModule.intent.uri === targetUrl) {\n // console.log('vvvvvvvvvvvv', it.state, it.routerModule.intent.uri);\n // }\n // });\n await simpleBootFront.goRouting(targetUrl);\n await new Promise(r => setTimeout(r, 0)); // <--\uC911\uC694: \uC774\uAC70 \uB123\uC5B4\uC57C\uC9C0 \uB450\uBC88\uBD88\uB7EC\uC9C0\uB294\uAC8C \uC5C6\uC5B4\uC9C0\uB294\uB4EF? \uBB50\uC9C0 event loop \uBCC0\uACBD\uB41C\uAC74\uAC00?\n // TODO: \uC635\uC158\uC73C\uB85C \uC774\uAC70 \uD0A4\uACE0 \uB044\uACE0\uD560\uC218\uC788\uAC8C \uD574\uC57C\uB420\uAE4C..?\n // simpleBootFront.routingSubjectObservable.pipe(\n // filter((it) =>\n // it.state === 'end' &&\n // typeof it.routerModule.intent.uri === 'string' &&\n // targetUrl.endsWith(it.routerModule.intent.uri)\n // ),\n // // delay(1000),\n // first()\n // );\n const data = await MessageInternal.firstValueFrom(\n // @ts-ignore\n simpleBootFront.routingObservable.pipe(\n // @ts-ignore\n MessageOperator.filter(\n (it) =>\n it.triggerPoint === 'end' &&\n typeof it.routerModule.intent.uri === 'string' &&\n targetUrl.endsWith(it.routerModule.intent.uri)\n ),\n // delay(1000),\n MessageOperator.first()\n )\n );\n // console.log('rrrrrssss');\n // console.log('rrrrrssss122');\n // await new Promise(r => setTimeout(r, 5000)); // <--\uC911\uC694: \uC774\uAC70 \uB123\uC5B4\uC57C\uC9C0 \uB450\uBC88\uBD88\uB7EC\uC9C0\uB294\uAC8C \uC5C6\uC5B4\uC9C0\uB294\uB4EF? \uBB50\uC9C0 event loop \uBCC0\uACBD\uB41C\uAC74\uAC00?\n const html = this.makeHTML(simpleBootFront);\n await this.writeOkHtmlAndEnd({ rr }, html);\n } finally {\n (simpleBootFront.option.window as any).ssrUse = false;\n delete (simpleBootFront.option.window as any).server_side_data;\n // console.log('--------->', simpleBootFront.option.window)\n // simpleBootFront.ninitWriteRootRouter();\n // ((simpleBootFront as any).jsdom as JSDOM.JSDOM)?.reconfigure({url: '/' });\n // simpleBootFront.option.window.location.href = 'about:blank';\n // console.log('ddddddddd', (simpleBootFront as any).generation, this.poolGeneration)\n if ((simpleBootFront as any).generation < this.poolGeneration) {\n // Stale instance, destroy it\n const jsdom = (simpleBootFront as any).jsdom as JSDOM.JSDOM | undefined;\n jsdom?.window.close();\n const index = this.simpleBootFrontPool.indexOf(simpleBootFront);\n if (index > -1) {\n this.simpleBootFrontPool.splice(index, 1);\n }\n // Create a new one to maintain pool size\n this.pushQueue();\n } else {\n // Current instance, return to queue\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n // simpleBootFront.option.window.document.body.innerHTML = this.rootJSDOM.window.document.body.innerHTML;\n // simpleBootFront.writeRootRouter()\n // await simpleBootFront.goRouting('/');\n\n // ((simpleBootFront as any).jsdom as JSDOM.JSDOM)?.reconfigure({url: this.welcomUrl });\n\n // simpleBootFront.option.window.location.href = this.welcomUrl;\n // simpleBootFront.option.window.document.documentElement.outerHTML = this.indexHTML;\n // this.simpleBootFrontQueue.enqueue(simpleBootFront);\n // await new Promise((re, r) => setTimeout(() => re(true), 10000));\n // new Promise((re, r) => setTimeout(() => re(true), 10000)).then(it => {\n // console.log('ddddddddddd')\n // });\n // this.simpleBootFrontPool.delete(simpleBootFront.option.name!);\n // if (isMainThread) { // \uBA54\uC778 \uC2A4\uB808\uB4DC\n // console.log('file-->', __filename)\n // const worker = new Worker(__filename);\n // worker.on('message', (value: any) => {\n // console.log('\uC6CC\uCEE4\uB85C\uBD80\uD130', value)\n // })\n // worker.on('exit', (value: any) => { // parentPort.close()\uAC00 \uC77C\uC5B4\uB098\uBA74 \uC774\uBCA4\uD2B8 \uBC1C\uC0DD\n // console.log('\uC6CC\uCEE4 \uB05D~');\n // })\n // worker.postMessage('ping'); // \uC6CC\uCEE4\uC2A4\uB808\uB4DC\uC5D0\uAC8C \uBA54\uC138\uC9C0\uB97C \uBCF4\uB0B8\uB2E4.\n // } else { // \uC6CC\uCEE4\uC2A4\uB808\uB4DC\n // parentPort.on('message', (value: any) => {\n // console.log(\"\uBD80\uBAA8\uB85C\uBD80\uD130\", value);\n // parentPort.postMessage('pong');\n // parentPort.close(); // \uC6CC\uCEE4\uC2A4\uB808\uB4DC \uC885\uB8CC\uB77C\uACE0 \uBA54\uC778\uC2A4\uB808\uB4DC\uC5D0 \uC54C\uB824\uC918\uC57C exit\uC774\uBCA4\uD2B8 \uBC1C\uC0DD\n // })\n // }\n\n //worker thrad\n // const workerPath = path.join(__dirname, 'SSRWorker.js');\n // const worker = new Worker(workerPath);\n // worker.once('message', (value: any) => {\n // console.log('\uC6CC\uCEE4\uB85C\uBD80\uD130', value)\n // });\n // const receiveWorker = new Worker('/Users/hyunhakim/source/visualkhh/pet-space/libs/simple-boot-http-ssr/dist/filters/SSRCreatorWorker.js');\n // receiveWorker.on('message', (msg: JSDOM.JSDOM)=>{\n // console.log('\uC6CC\uCEE4\uB85C\uBD80\uD130', msg, msg.window.document.body.innerHTML)\n // console.log('a message is sent! : ', msg)\n //\n // });\n //\n // receiveWorker.on('error', err=>{\n // console.error(err);\n // })\n //\n // receiveWorker.on('exit', ()=>console.log('exited!'));\n // receiveWorker.postMessage(\n // {\n // frontDistPath: this.factory.frontDistPath,\n // frontDistIndexFileName: this.factory.frontDistIndexFileName,\n // }\n // );\n\n // const myWorkers = this.workerTs({});\n // myWorkers.postMessage(this);\n // myWorkers.on('message', (value: SimpleBootFront) => {\n // this.pushQueue(value);\n // })\n // this\n // this.pushQueue(simpleBootFront).then(it => {\n // console.log('deee')\n // });\n // console.log('-1->', simpleBootFront.option.window.location.href);\n // simpleBootFront.option.window.location.href = this.welcomUrl;\n // simpleBootFront.option.window.location.reload();\n // console.log('-2->', simpleBootFront.option.window.location.href);\n // simpleBootFront.option.window.location.reload();\n // console.log('-3->', simpleBootFront.option.window.location.href);\n // this.simpleBootFrontQueue.enqueue(simpleBootFront);\n // await this.makeJsdom();\n // simpleBootFront.option.window.location.href = this.welcomUrl;\n }\n // console.log('----doen')\n return false;\n } else {\n // console.log('----doen2')\n return true;\n }\n }\n\n // const e = Expression.Path.pathNameData(rr.reqUrlPathName, intent.getRouterPath())\n // console.log('------intent', rr.reqUrl, rr.reqUrlPathName, intent.module, intent.getRouterPath(), e)\n // simpleBootFront.option.window.document.documentElemenh\n // \"dr-\"\uB85C \uC2DC\uC791\uD558\uB294 \uBAA8\uB4E0 attribute\uB97C \uAC00\uC9C4 element\uC5D0\uC11C \uD574\uB2F9 attribute\uB97C \uC81C\uAC70\n\n makeHTML(simpleBootFront: SimpleBootFront) {\n (simpleBootFront.option.window as any).document.querySelectorAll('*').forEach((el:HTMLElement )=> {\n Array.from(el.attributes).forEach(attr => {\n if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {\n el.removeAttribute(attr.name);\n }\n });\n });\n let html = simpleBootFront.option.window.document.documentElement.outerHTML;\n html = '<!DOCTYPE html>' + html;\n html = html.replace(/\\$\\{[\\s\\S]*?\\}\\$/g, '');\n const serverSideData = (simpleBootFront.option.window as any).server_side_data;\n if (serverSideData) {\n const data = Object.entries(serverSideData)\n .map(([k, v]) => {\n if (typeof v === 'string') {\n return `window.server_side_data.${k} = ${v}`;\n } else {\n return `window.server_side_data.${k} = ${JSON.stringify(v)}`;\n }\n })\n .join(';');\n if (data) {\n html = html.replace('</head>', `<script> window.server_side_data={}; ${data}; </script></head>`);\n }\n }\n return html;\n }\n async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }: { rr: RequestResponse; status?: HttpStatus }, html: string) {\n // rr.res.writeHead(status, {[HttpHeaders.ContentType]: Mimes.TextHtml});\n rr.resStatusCode(status);\n rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);\n await rr.resEnd(html);\n }\n\n async proceedAfter({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n // console.log('done--------', sw)\n return true;\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAA4B;AAE5B,kBAAmG;AACnG,8BAAiC;AAEjC,mBAAsB;AACtB,wBAA2B;AAK3B,2BAA8B;AAC9B,wBAA+B;AAoBxB,MAAM,UAA4B;AAAA,EAQvC,YACS,QACA,kBACP;AAFO;AACA;AATT,SAAQ,sBAAyC,CAAC;AAClD,SAAQ,uBAAuB,IAAI,+BAAoC;AAEvE,SAAQ,YAAY;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AO,oBAAoB;AAC3B,WAAO,KAAK,QAAQ,qBAAqB,EAAE;AAC3C,UAAM,iBAAkB,gBAAgB,OAAO,OAAe;AAC9D,QAAI,gBAAgB;AAClB,YAAM,OAAO,OAAO,QAAQ,cAAc,EACvC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AACf,YAAI,OAAO,MAAM,UAAU;AACzB,iBAAO,2BAA2B,CAAC,MAAM,CAAC;AAAA,QAC5C,OAAO;AACL,iBAAO,2BAA2B,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;AAAA,QAC5D;AAAA,MACF,CAAC,EACA,KAAK,GAAG;AACX,UAAI,MAAM;AACR,eAAO,KAAK,QAAQ,WAAW,wCAAwC,IAAI,oBAAoB;AAAA,MACjG;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EACA,MAAM,kBAAkB,EAAE,IAAI,SAAS,6BAAW,GAAG,GAAiD,MAAc;AAElH,OAAG,cAAc,MAAM;AACvB,OAAG,aAAa,+BAAY,aAAa,mBAAM,QAAQ;AACvD,UAAM,GAAG,OAAO,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,aAAa,EAAE,IAAI,IAAI,GAAkF;AAE7G,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';\nimport { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';\nimport { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';\nimport { ConstructorType, AsyncBlockingQueue, RandomUtils, firstValueFrom } from '@dooboostore/core';\nimport { first } from '@dooboostore/core/message/operators';\nimport { JsdomInitializer } from '../initializers/JsdomInitializer';\nimport { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';\nimport { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';\nimport { HttpStatus } from '@dooboostore/simple-boot-http-server/codes/HttpStatus';\nimport { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';\nimport { SimFrontOption } from '@dooboostore/simple-boot-front/option/SimFrontOption';\nimport { SimpleBootFront } from '@dooboostore/simple-boot-front/SimpleBootFront';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render';\n\nexport type FactoryAndParams = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n factorySimFrontOption: (window: any) => SimFrontOption;\n factory: SimpleBootHttpSSRFactory;\n poolOption: {\n max: number;\n min: number;\n clearIntervalTime?: number;\n };\n using: ConstructorType<any>[];\n domExcludes?: ConstructorType<any>[];\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n simpleBootFront?: {\n notFoundError?: boolean;\n };\n};\n\nexport class SSRFilter implements Filter {\n private simpleBootFrontPool: SimpleBootFront[] = [];\n private simpleBootFrontQueue = new AsyncBlockingQueue<SimpleBootFront>();\n private indexHTML: string;\n private welcomUrl = 'http://localhost';\n private poolGeneration = 0;\n private intervalId?: NodeJS.Timeout;\n\n constructor(\n public config: FactoryAndParams,\n public otherInstanceSim?: Map<ConstructorType<any>, any>\n ) {\n config.frontDistIndexFileName = config.frontDistIndexFileName || 'index.html';\n this.indexHTML = JsdomInitializer.loadFile(this.config.frontDistPath, config.frontDistIndexFileName);\n }\n\n async onInit(app: SimpleBootHttpServer) {\n for (let i = 0; i < this.config.poolOption.min; i++) {\n await this.pushQueue();\n }\n\n if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {\n this.intervalId = setInterval(() => {\n this.poolGeneration++;\n }, this.config.poolOption.clearIntervalTime);\n }\n // console.log('SimpleBootHttpSSRFactory init success ', + this.simpleBootFrontPool.length)\n }\n\n async onDestroy() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n // this.simpleBootFrontQueue.clear();\n this.simpleBootFrontPool.forEach(front => {\n (front as any).jsdom?.window.close();\n });\n this.simpleBootFrontPool = [];\n }\n\n // workerTs(workerOptions: WorkerOptions) {\n // workerOptions.eval = true;\n // if (!workerOptions.workerData) {\n // workerOptions.workerData = {};\n // }\n // workerOptions.workerData.__filename = '/Users/hyunhakim/source/visualkhh/pet-space/libs/simple-boot-http-ssr/dist/filters/SSRCreatorWorker.js';\n // return new Worker(` const wk = require('worker_threads'); require('ts-node').register(); let file = wk.workerData.__filename; require(file); `, workerOptions,);\n // }\n\n async makeJsdom() {\n const jsdom = await new JsdomInitializer(\n this.config.frontDistPath,\n this.config.frontDistIndexFileName || 'index.html',\n { url: this.welcomUrl }\n ).run();\n return jsdom;\n }\n\n async makeFront(jsdom: JSDOM.JSDOM) {\n const name = RandomUtils.uuid();\n // const jsdom = await this.makeJsdom();\n const window = jsdom.window as unknown as Window & typeof globalThis;\n (window as any).ssrUse = false;\n const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));\n const simpleBootFront = await this.config.factory.create(option, this.config.using, this.config.domExcludes);\n simpleBootFront.run(this.otherInstanceSim);\n (simpleBootFront as any).jsdom = jsdom;\n (simpleBootFront as any).generation = this.poolGeneration;\n return simpleBootFront;\n }\n\n enqueueFrontApp(simpleBootFront: SimpleBootFront) {\n // this.simpleBootFrontPool.set(simpleBootFront.option.name!, simpleBootFront);\n this.simpleBootFrontPool.push(simpleBootFront);\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n\n // async pushQueue(destorFront?: SimpleBootFront) {\n // if (destorFront) {\n // this.simpleBootFrontPool.delete(destorFront.option.name!);\n // }\n async pushQueue() {\n if (this.simpleBootFrontPool.length < this.config.poolOption.max) {\n this.enqueueFrontApp(await this.makeFront(await this.makeJsdom()));\n }\n }\n\n async proceedBefore({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return false;\n }\n if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {\n if (this.simpleBootFrontQueue.isEmpty()) {\n await this.pushQueue();\n }\n const simpleBootFront = await this.simpleBootFrontQueue.dequeue();\n try {\n // console.log('SSRFilter before-->' , simpleBootFront.option.name, 'poolLength:',this.simpleBootFrontPool.size);\n (simpleBootFront.option.window as any).ssrUse = true;\n delete (simpleBootFront.option.window as any).server_side_data;\n\n const url = rr.reqUrlObj({ host: 'localhost' });\n if (this.config.simpleBootFront?.notFoundError) {\n // intent router check first\n const intent = await simpleBootFront.routingRouterModule(url.pathname);\n // route\uB97C \uBABB\uCC3E\uC740\uC0C1\uD0DC\uC5D0\uC11C router path\uAE4C\uC9C0 \uC548\uB9DE\uC73C\uBA74 404 \uCC98\uB9AC\uD55C\uB2E4. route\uB791 router\uB791 \uB2E4\uB974\uB2C8\uAE50 \uD5DB\uAC08\uB9AC\uC9C0\uB9D0\uB3C4\uB85D\n if (intent.module === undefined && !intent.getRouterPathData(rr.reqUrlPathName)) {\n throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });\n }\n }\n\n // runRouting!!\n const targetUrl = url.toString();\n // console.log('rrrrr');\n // simpleBootFront.routingSubjectObservable.subscribe(it => {\n // if (it.state === 'end' && it.routerModule.intent.uri === targetUrl) {\n // console.log('vvvvvvvvvvvv', it.state, it.routerModule.intent.uri);\n // }\n // });\n await simpleBootFront.goRouting(targetUrl);\n await new Promise(r => setTimeout(r, 0)); // <--\uC911\uC694: \uC774\uAC70 \uB123\uC5B4\uC57C\uC9C0 \uB450\uBC88\uBD88\uB7EC\uC9C0\uB294\uAC8C \uC5C6\uC5B4\uC9C0\uB294\uB4EF? \uBB50\uC9C0 event loop \uBCC0\uACBD\uB41C\uAC74\uAC00?\n // TODO: \uC635\uC158\uC73C\uB85C \uC774\uAC70 \uD0A4\uACE0 \uB044\uACE0\uD560\uC218\uC788\uAC8C \uD574\uC57C\uB420\uAE4C..?\n // simpleBootFront.routingSubjectObservable.pipe(\n // filter((it) =>\n // it.state === 'end' &&\n // typeof it.routerModule.intent.uri === 'string' &&\n // targetUrl.endsWith(it.routerModule.intent.uri)\n // ),\n // // delay(1000),\n // first()\n // );\n const data = await firstValueFrom(\n // @ts-ignore\n simpleBootFront.routingObservable.pipe(\n // @ts-ignore\n MessageOperator.filter(\n (it) =>\n it.triggerPoint === 'end' &&\n typeof it.routerModule.intent.uri === 'string' &&\n targetUrl.endsWith(it.routerModule.intent.uri)\n ),\n // delay(1000),\n first()\n )\n );\n // console.log('rrrrrssss');\n // console.log('rrrrrssss122');\n // await new Promise(r => setTimeout(r, 5000)); // <--\uC911\uC694: \uC774\uAC70 \uB123\uC5B4\uC57C\uC9C0 \uB450\uBC88\uBD88\uB7EC\uC9C0\uB294\uAC8C \uC5C6\uC5B4\uC9C0\uB294\uB4EF? \uBB50\uC9C0 event loop \uBCC0\uACBD\uB41C\uAC74\uAC00?\n const html = this.makeHTML(simpleBootFront);\n await this.writeOkHtmlAndEnd({ rr }, html);\n } finally {\n (simpleBootFront.option.window as any).ssrUse = false;\n delete (simpleBootFront.option.window as any).server_side_data;\n // console.log('--------->', simpleBootFront.option.window)\n // simpleBootFront.ninitWriteRootRouter();\n // ((simpleBootFront as any).jsdom as JSDOM.JSDOM)?.reconfigure({url: '/' });\n // simpleBootFront.option.window.location.href = 'about:blank';\n // console.log('ddddddddd', (simpleBootFront as any).generation, this.poolGeneration)\n if ((simpleBootFront as any).generation < this.poolGeneration) {\n // Stale instance, destroy it\n const jsdom = (simpleBootFront as any).jsdom as JSDOM.JSDOM | undefined;\n jsdom?.window.close();\n const index = this.simpleBootFrontPool.indexOf(simpleBootFront);\n if (index > -1) {\n this.simpleBootFrontPool.splice(index, 1);\n }\n // Create a new one to maintain pool size\n this.pushQueue();\n } else {\n // Current instance, return to queue\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n // simpleBootFront.option.window.document.body.innerHTML = this.rootJSDOM.window.document.body.innerHTML;\n // simpleBootFront.writeRootRouter()\n // await simpleBootFront.goRouting('/');\n\n // ((simpleBootFront as any).jsdom as JSDOM.JSDOM)?.reconfigure({url: this.welcomUrl });\n\n // simpleBootFront.option.window.location.href = this.welcomUrl;\n // simpleBootFront.option.window.document.documentElement.outerHTML = this.indexHTML;\n // this.simpleBootFrontQueue.enqueue(simpleBootFront);\n // await new Promise((re, r) => setTimeout(() => re(true), 10000));\n // new Promise((re, r) => setTimeout(() => re(true), 10000)).then(it => {\n // console.log('ddddddddddd')\n // });\n // this.simpleBootFrontPool.delete(simpleBootFront.option.name!);\n // if (isMainThread) { // \uBA54\uC778 \uC2A4\uB808\uB4DC\n // console.log('file-->', __filename)\n // const worker = new Worker(__filename);\n // worker.on('message', (value: any) => {\n // console.log('\uC6CC\uCEE4\uB85C\uBD80\uD130', value)\n // })\n // worker.on('exit', (value: any) => { // parentPort.close()\uAC00 \uC77C\uC5B4\uB098\uBA74 \uC774\uBCA4\uD2B8 \uBC1C\uC0DD\n // console.log('\uC6CC\uCEE4 \uB05D~');\n // })\n // worker.postMessage('ping'); // \uC6CC\uCEE4\uC2A4\uB808\uB4DC\uC5D0\uAC8C \uBA54\uC138\uC9C0\uB97C \uBCF4\uB0B8\uB2E4.\n // } else { // \uC6CC\uCEE4\uC2A4\uB808\uB4DC\n // parentPort.on('message', (value: any) => {\n // console.log(\"\uBD80\uBAA8\uB85C\uBD80\uD130\", value);\n // parentPort.postMessage('pong');\n // parentPort.close(); // \uC6CC\uCEE4\uC2A4\uB808\uB4DC \uC885\uB8CC\uB77C\uACE0 \uBA54\uC778\uC2A4\uB808\uB4DC\uC5D0 \uC54C\uB824\uC918\uC57C exit\uC774\uBCA4\uD2B8 \uBC1C\uC0DD\n // })\n // }\n\n //worker thrad\n // const workerPath = path.join(__dirname, 'SSRWorker.js');\n // const worker = new Worker(workerPath);\n // worker.once('message', (value: any) => {\n // console.log('\uC6CC\uCEE4\uB85C\uBD80\uD130', value)\n // });\n // const receiveWorker = new Worker('/Users/hyunhakim/source/visualkhh/pet-space/libs/simple-boot-http-ssr/dist/filters/SSRCreatorWorker.js');\n // receiveWorker.on('message', (msg: JSDOM.JSDOM)=>{\n // console.log('\uC6CC\uCEE4\uB85C\uBD80\uD130', msg, msg.window.document.body.innerHTML)\n // console.log('a message is sent! : ', msg)\n //\n // });\n //\n // receiveWorker.on('error', err=>{\n // console.error(err);\n // })\n //\n // receiveWorker.on('exit', ()=>console.log('exited!'));\n // receiveWorker.postMessage(\n // {\n // frontDistPath: this.factory.frontDistPath,\n // frontDistIndexFileName: this.factory.frontDistIndexFileName,\n // }\n // );\n\n // const myWorkers = this.workerTs({});\n // myWorkers.postMessage(this);\n // myWorkers.on('message', (value: SimpleBootFront) => {\n // this.pushQueue(value);\n // })\n // this\n // this.pushQueue(simpleBootFront).then(it => {\n // console.log('deee')\n // });\n // console.log('-1->', simpleBootFront.option.window.location.href);\n // simpleBootFront.option.window.location.href = this.welcomUrl;\n // simpleBootFront.option.window.location.reload();\n // console.log('-2->', simpleBootFront.option.window.location.href);\n // simpleBootFront.option.window.location.reload();\n // console.log('-3->', simpleBootFront.option.window.location.href);\n // this.simpleBootFrontQueue.enqueue(simpleBootFront);\n // await this.makeJsdom();\n // simpleBootFront.option.window.location.href = this.welcomUrl;\n }\n // console.log('----doen')\n return false;\n } else {\n // console.log('----doen2')\n return true;\n }\n }\n\n // const e = Expression.Path.pathNameData(rr.reqUrlPathName, intent.getRouterPath())\n // console.log('------intent', rr.reqUrl, rr.reqUrlPathName, intent.module, intent.getRouterPath(), e)\n // simpleBootFront.option.window.document.documentElemenh\n // \"dr-\"\uB85C \uC2DC\uC791\uD558\uB294 \uBAA8\uB4E0 attribute\uB97C \uAC00\uC9C4 element\uC5D0\uC11C \uD574\uB2F9 attribute\uB97C \uC81C\uAC70\n\n makeHTML(simpleBootFront: SimpleBootFront) {\n (simpleBootFront.option.window as any).document.querySelectorAll('*').forEach((el:HTMLElement )=> {\n Array.from(el.attributes).forEach(attr => {\n if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {\n el.removeAttribute(attr.name);\n }\n });\n });\n let html = simpleBootFront.option.window.document.documentElement.outerHTML;\n html = '<!DOCTYPE html>' + html;\n html = html.replace(/\\$\\{[\\s\\S]*?\\}\\$/g, '');\n const serverSideData = (simpleBootFront.option.window as any).server_side_data;\n if (serverSideData) {\n const data = Object.entries(serverSideData)\n .map(([k, v]) => {\n if (typeof v === 'string') {\n return `window.server_side_data.${k} = ${v}`;\n } else {\n return `window.server_side_data.${k} = ${JSON.stringify(v)}`;\n }\n })\n .join(';');\n if (data) {\n html = html.replace('</head>', `<script> window.server_side_data={}; ${data}; </script></head>`);\n }\n }\n return html;\n }\n async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }: { rr: RequestResponse; status?: HttpStatus }, html: string) {\n // rr.res.writeHead(status, {[HttpHeaders.ContentType]: Mimes.TextHtml});\n rr.resStatusCode(status);\n rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);\n await rr.resEnd(html);\n }\n\n async proceedAfter({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n // console.log('done--------', sw)\n return true;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAA4B;AAE5B,kBAAiF;AACjF,uBAAsB;AACtB,8BAAiC;AAEjC,mBAAsB;AACtB,wBAA2B;AAK3B,2BAA8B;AAC9B,wBAA+B;AAoBxB,MAAM,UAA4B;AAAA,EAQvC,YACS,QACA,kBACP;AAFO;AACA;AATT,SAAQ,sBAAyC,CAAC;AAClD,SAAQ,uBAAuB,IAAI,+BAAoC;AAEvE,SAAQ,YAAY;AACpB,SAAQ,iBAAiB;AAOvB,WAAO,yBAAyB,OAAO,0BAA0B;AACjE,SAAK,YAAY,yCAAiB,SAAS,KAAK,OAAO,eAAe,OAAO,sBAAsB;AAAA,EACrG;AAAA,EAEA,MAAM,OAAO,KAA2B;AACtC,aAAS,IAAI,GAAG,IAAI,KAAK,OAAO,WAAW,KAAK,KAAK;AACnD,Y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AC,MAAM,CAAC;AAAA,QAC5C,OAAO;AACL,iBAAO,2BAA2B,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;AAAA,QAC5D;AAAA,MACF,CAAC,EACA,KAAK,GAAG;AACX,UAAI,MAAM;AACR,eAAO,KAAK,QAAQ,WAAW,wCAAwC,IAAI,oBAAoB;AAAA,MACjG;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EACA,MAAM,kBAAkB,EAAE,IAAI,SAAS,6BAAW,GAAG,GAAiD,MAAc;AAElH,OAAG,cAAc,MAAM;AACvB,OAAG,aAAa,+BAAY,aAAa,mBAAM,QAAQ;AACvD,UAAM,GAAG,OAAO,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,aAAa,EAAE,IAAI,IAAI,GAAkF;AAE7G,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
@@ -15,19 +15,20 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var SSRLinkDomDomFilter_exports = {};
19
- __export(SSRLinkDomDomFilter_exports, {
20
- SSRLinkDomDomFilter: () => SSRLinkDomDomFilter
18
+ var SSRLinkDomFilter_exports = {};
19
+ __export(SSRLinkDomFilter_exports, {
20
+ SSRLinkDomFilter: () => SSRLinkDomFilter
21
21
  });
22
- module.exports = __toCommonJS(SSRLinkDomDomFilter_exports);
22
+ module.exports = __toCommonJS(SSRLinkDomFilter_exports);
23
23
  var import_HttpHeaders = require("@dooboostore/simple-boot-http-server/codes/HttpHeaders");
24
24
  var import_core = require("@dooboostore/core");
25
+ var import_operators = require("@dooboostore/core/message/operators");
25
26
  var import_Mimes = require("@dooboostore/simple-boot-http-server/codes/Mimes");
26
27
  var import_HttpStatus = require("@dooboostore/simple-boot-http-server/codes/HttpStatus");
27
28
  var import_NotFoundError = require("@dooboostore/simple-boot-http-server/errors/NotFoundError");
28
29
  var import_dom_render = require("@dooboostore/dom-render");
29
30
  var import_LinkedomInitializer = require("../initializers/LinkedomInitializer");
30
- class SSRLinkDomDomFilter {
31
+ class SSRLinkDomFilter {
31
32
  constructor(config, otherInstanceSim) {
32
33
  this.config = config;
33
34
  this.otherInstanceSim = otherInstanceSim;
@@ -104,15 +105,15 @@ class SSRLinkDomDomFilter {
104
105
  const targetUrl = url.toString();
105
106
  await simpleBootFront.goRouting(targetUrl);
106
107
  await new Promise((r) => setTimeout(r, 0));
107
- const data = await import_core.MessageInternal.firstValueFrom(
108
+ const data = await (0, import_core.firstValueFrom)(
108
109
  // @ts-ignore
109
110
  simpleBootFront.routingObservable.pipe(
110
111
  // @ts-ignore
111
- import_core.MessageOperator.filter(
112
+ MessageOperator.filter(
112
113
  (it) => it.triggerPoint === "end" && typeof it.routerModule.intent.uri === "string" && targetUrl.endsWith(it.routerModule.intent.uri)
113
114
  ),
114
115
  // delay(1000),
115
- import_core.MessageOperator.first()
116
+ (0, import_operators.first)()
116
117
  )
117
118
  );
118
119
  const html = this.makeHTML(simpleBootFront);
@@ -174,6 +175,6 @@ class SSRLinkDomDomFilter {
174
175
  }
175
176
  // Annotate the CommonJS export names for ESM import in node:
176
177
  0 && (module.exports = {
177
- SSRLinkDomDomFilter
178
+ SSRLinkDomFilter
178
179
  });
179
- //# sourceMappingURL=SSRLinkDomDomFilter.js.map
180
+ //# sourceMappingURL=SSRLinkDomFilter.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/filters/SSRLinkDomFilter.ts"],
4
+ "sourcesContent": ["import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';\nimport { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';\nimport { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';\nimport { ConstructorType, AsyncBlockingQueue, RandomUtils, firstValueFrom } from '@dooboostore/core';\nimport { first } from '@dooboostore/core/message/operators';\nimport { JsdomInitializer } from '../initializers/JsdomInitializer';\nimport { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';\nimport { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';\nimport { HttpStatus } from '@dooboostore/simple-boot-http-server/codes/HttpStatus';\nimport { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';\nimport { SimFrontOption } from '@dooboostore/simple-boot-front/option/SimFrontOption';\nimport { SimpleBootFront } from '@dooboostore/simple-boot-front/SimpleBootFront';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render';\nimport { parseHTML } from 'linkedom';\nimport { LinkedomInitializer } from '../initializers/LinkedomInitializer';\n\nexport type LinkDomFactoryAndParams = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n factorySimFrontOption: (window: any) => SimFrontOption;\n factory: SimpleBootHttpSSRFactory;\n poolOption: {\n max: number;\n min: number;\n clearIntervalTime?: number;\n };\n using: ConstructorType<any>[];\n domExcludes?: ConstructorType<any>[];\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n simpleBootFront?: {\n notFoundError?: boolean;\n };\n};\n\nexport class SSRLinkDomFilter implements Filter {\n private simpleBootFrontPool: SimpleBootFront[] = [];\n private simpleBootFrontQueue = new AsyncBlockingQueue<SimpleBootFront>();\n // private indexHTML: string;\n private welcomUrl = 'http://localhost';\n private poolGeneration = 0;\n private intervalId?: NodeJS.Timeout;\n\n constructor(\n public config: LinkDomFactoryAndParams,\n public otherInstanceSim?: Map<ConstructorType<any>, any>\n ) {\n config.frontDistIndexFileName = config.frontDistIndexFileName || 'index.html';\n // this.indexHTML = JsdomInitializer.loadFile(this.config.frontDistPath, config.frontDistIndexFileName);\n }\n\n async onInit(app: SimpleBootHttpServer) {\n for (let i = 0; i < this.config.poolOption.min; i++) {\n await this.pushQueue();\n }\n\n if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {\n this.intervalId = setInterval(() => {\n this.poolGeneration++;\n }, this.config.poolOption.clearIntervalTime);\n }\n }\n\n async onDestroy() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n // this.simpleBootFrontQueue.clear();\n this.simpleBootFrontPool.forEach(front => {\n (front as any).jsdom?.window.close();\n });\n this.simpleBootFrontPool = [];\n }\n\n async makePage() {\n return new LinkedomInitializer(\n this.config.frontDistPath,\n this.config.frontDistIndexFileName || 'index.html',\n { url: this.welcomUrl }\n ).run();\n // const jsdom = await new JsdomInitializer(\n // this.config.frontDistPath,\n // this.config.frontDistIndexFileName || 'index.html',\n // { url: this.welcomUrl }\n // ).run();\n // return jsdom;\n }\n\n async makeFront(window: Window) {\n const name = RandomUtils.uuid();\n (window as any).ssrUse = false;\n const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));\n const simpleBootFront = await this.config.factory.create(option, this.config.using, this.config.domExcludes);\n simpleBootFront.run(this.otherInstanceSim);\n (simpleBootFront as any).generation = this.poolGeneration;\n return simpleBootFront;\n }\n\n enqueueFrontApp(simpleBootFront: SimpleBootFront) {\n // this.simpleBootFrontPool.set(simpleBootFront.option.name!, simpleBootFront);\n this.simpleBootFrontPool.push(simpleBootFront);\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n async pushQueue() {\n if (this.simpleBootFrontPool.length < this.config.poolOption.max) {\n this.enqueueFrontApp(await this.makeFront(await this.makePage()));\n }\n }\n\n async proceedBefore({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return false;\n }\n if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {\n if (this.simpleBootFrontQueue.isEmpty()) {\n await this.pushQueue();\n }\n const simpleBootFront = await this.simpleBootFrontQueue.dequeue();\n try {\n (simpleBootFront.option.window as any).ssrUse = true;\n delete (simpleBootFront.option.window as any).server_side_data;\n const url = rr.reqUrlObj({ host: 'localhost' });\n if (this.config.simpleBootFront?.notFoundError) {\n // intent router check first\n const intent = await simpleBootFront.routingRouterModule(url.pathname);\n // route\uB97C \uBABB\uCC3E\uC740\uC0C1\uD0DC\uC5D0\uC11C router path\uAE4C\uC9C0 \uC548\uB9DE\uC73C\uBA74 404 \uCC98\uB9AC\uD55C\uB2E4. route\uB791 router\uB791 \uB2E4\uB974\uB2C8\uAE50 \uD5DB\uAC08\uB9AC\uC9C0\uB9D0\uB3C4\uB85D\n if (intent.module === undefined && !intent.getRouterPathData(rr.reqUrlPathName)) {\n throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });\n }\n }\n\n // runRouting!!\n const targetUrl = url.toString();\n await simpleBootFront.goRouting(targetUrl);\n await new Promise(r => setTimeout(r, 0)); // <--\uC911\uC694: \uC774\uAC70 \uB123\uC5B4\uC57C\uC9C0 \uB450\uBC88\uBD88\uB7EC\uC9C0\uB294\uAC8C \uC5C6\uC5B4\uC9C0\uB294\uB4EF? \uBB50\uC9C0 event loop \uBCC0\uACBD\uB41C\uAC74\uAC00?\n\n\n // simpleBootFront.routingSubjectObservable.subscribe(it=>{\n // console.log('zzzzzzzzzzzzzzzzzzz', it);\n // if (it.triggerPoint==='end') {\n // console.log('zzz@@', it.routerModule.intent);\n // }\n // })\n\n const data = await firstValueFrom(\n // @ts-ignore\n simpleBootFront.routingObservable.pipe(\n // @ts-ignore\n MessageOperator.filter(\n (it) =>\n it.triggerPoint === 'end' &&\n typeof it.routerModule.intent.uri === 'string' &&\n targetUrl.endsWith(it.routerModule.intent.uri)\n ),\n // delay(1000),\n first()\n )\n );\n // console.log('???????done');\n const html = this.makeHTML(simpleBootFront);\n await this.writeOkHtmlAndEnd({ rr }, html);\n } finally {\n (simpleBootFront.option.window as any).ssrUse = false;\n delete (simpleBootFront.option.window as any).server_side_data;\n if ((simpleBootFront as any).generation < this.poolGeneration) {\n // Stale instance, destroy it\n const jsdom = (simpleBootFront as any).jsdom as JSDOM.JSDOM | undefined;\n jsdom?.window.close();\n const index = this.simpleBootFrontPool.indexOf(simpleBootFront);\n if (index > -1) {\n this.simpleBootFrontPool.splice(index, 1);\n }\n this.pushQueue();\n } else {\n // Current instance, return to queue\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n }\n return false;\n } else {\n return true;\n }\n }\n\n makeHTML(simpleBootFront: SimpleBootFront) {\n (simpleBootFront.option.window as any).document.querySelectorAll('*').forEach((el:HTMLElement )=> {\n Array.from(el.attributes).forEach(attr => {\n if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {\n el.removeAttribute(attr.name);\n }\n });\n });\n let html = simpleBootFront.option.window.document.documentElement.outerHTML;\n html = '<!DOCTYPE html>' + html;\n html = html.replace(/\\$\\{[\\s\\S]*?\\}\\$/g, '');\n const serverSideData = (simpleBootFront.option.window as any).server_side_data;\n if (serverSideData) {\n const data = Object.entries(serverSideData)\n .map(([k, v]) => {\n if (typeof v === 'string') {\n return `window.server_side_data.${k} = ${v}`;\n } else {\n return `window.server_side_data.${k} = ${JSON.stringify(v)}`;\n }\n })\n .join(';');\n if (data) {\n html = html.replace('</head>', `<script> window.server_side_data={}; ${data}; </script></head>`);\n }\n }\n return html;\n }\n async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }: { rr: RequestResponse; status?: HttpStatus }, html: string) {\n rr.resStatusCode(status);\n rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);\n await rr.resEnd(html);\n }\n\n async proceedAfter({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n return true;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAA4B;AAE5B,kBAAiF;AACjF,uBAAsB;AAGtB,mBAAsB;AACtB,wBAA2B;AAK3B,2BAA8B;AAC9B,wBAA+B;AAE/B,iCAAoC;AAoB7B,MAAM,iBAAmC;AAAA,EAQ9C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Q,cAAc,EACvC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AACf,YAAI,OAAO,MAAM,UAAU;AACzB,iBAAO,2BAA2B,CAAC,MAAM,CAAC;AAAA,QAC5C,OAAO;AACL,iBAAO,2BAA2B,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;AAAA,QAC5D;AAAA,MACF,CAAC,EACA,KAAK,GAAG;AACX,UAAI,MAAM;AACR,eAAO,KAAK,QAAQ,WAAW,wCAAwC,IAAI,oBAAoB;AAAA,MACjG;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EACA,MAAM,kBAAkB,EAAE,IAAI,SAAS,6BAAW,GAAG,GAAiD,MAAc;AAClH,OAAG,cAAc,MAAM;AACvB,OAAG,aAAa,+BAAY,aAAa,mBAAM,QAAQ;AACvD,UAAM,GAAG,OAAO,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,aAAa,EAAE,IAAI,IAAI,GAAkF;AAC7G,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,81 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var SSRSimpleWebComponentDomParserFilter_exports = {};
19
+ __export(SSRSimpleWebComponentDomParserFilter_exports, {
20
+ SSRSimpleWebComponentDomParserFilter: () => SSRSimpleWebComponentDomParserFilter
21
+ });
22
+ module.exports = __toCommonJS(SSRSimpleWebComponentDomParserFilter_exports);
23
+ var import_HttpHeaders = require("@dooboostore/simple-boot-http-server/codes/HttpHeaders");
24
+ var import_Mimes = require("@dooboostore/simple-boot-http-server/codes/Mimes");
25
+ var import_HttpStatus = require("@dooboostore/simple-boot-http-server/codes/HttpStatus");
26
+ var import_DomParserInitializer = require("../initializers/DomParserInitializer");
27
+ class SSRSimpleWebComponentDomParserFilter {
28
+ constructor(config) {
29
+ this.config = config;
30
+ this.welcomUrl = "http://localhost";
31
+ this.welcomUrl = config.welcomUrl || this.welcomUrl;
32
+ }
33
+ async onInit(app) {
34
+ }
35
+ async onDestroy() {
36
+ }
37
+ async proceedBefore({ rr }) {
38
+ if (this.config.ssrExcludeFilter?.(rr)) {
39
+ return false;
40
+ }
41
+ if (rr.reqHasAcceptHeader(import_Mimes.Mimes.TextHtml) || rr.reqHasAcceptHeader(import_Mimes.Mimes.All)) {
42
+ const url = rr.reqUrlObj({ host: "localhost" });
43
+ const targetUrl = url.toString() ?? this.welcomUrl;
44
+ console.log("SSRSimpleWebComponentDomParserFilter start");
45
+ const domParserInitializer = new import_DomParserInitializer.DomParserInitializer(this.config.frontDistPath, this.config.frontDistIndexFileName || "index.html", { url: targetUrl });
46
+ const window = await domParserInitializer.run();
47
+ try {
48
+ if (this.config.registerComponents) {
49
+ await this.config.registerComponents(window);
50
+ }
51
+ const html = this.makeHTML(window);
52
+ await this.writeOkHtmlAndEnd({ rr }, html);
53
+ } finally {
54
+ window.close();
55
+ domParserInitializer.destroy();
56
+ }
57
+ return false;
58
+ }
59
+ return true;
60
+ }
61
+ makeHTML(window) {
62
+ let html = window.document.documentElement.outerHTML;
63
+ if (!/^<!DOCTYPE html>/i.test(html)) {
64
+ html = "<!DOCTYPE html>\n" + html;
65
+ }
66
+ return html;
67
+ }
68
+ async writeOkHtmlAndEnd({ rr, status = import_HttpStatus.HttpStatus.Ok }, html) {
69
+ rr.resStatusCode(status);
70
+ rr.resSetHeader(import_HttpHeaders.HttpHeaders.ContentType, import_Mimes.Mimes.TextHtml);
71
+ await rr.resEnd(html);
72
+ }
73
+ async proceedAfter() {
74
+ return true;
75
+ }
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ SSRSimpleWebComponentDomParserFilter
80
+ });
81
+ //# sourceMappingURL=SSRSimpleWebComponentDomParserFilter.js.map