@dooboostore/simple-boot-http-server-ssr 1.0.12 → 1.0.14

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 (59) hide show
  1. package/README.MD +1 -3
  2. package/dist/cjs/filters/IntentSchemeFilter.js.map +2 -2
  3. package/dist/cjs/filters/SSRDomParserFilter.js +186 -0
  4. package/dist/cjs/filters/SSRDomParserFilter.js.map +7 -0
  5. package/dist/cjs/filters/SSRFilter.js +1 -1
  6. package/dist/cjs/filters/SSRFilter.js.map +2 -2
  7. package/dist/cjs/filters/SSRLinkDomDomFilter.js +183 -0
  8. package/dist/cjs/filters/SSRLinkDomDomFilter.js.map +7 -0
  9. package/dist/cjs/initializers/DomParserInitializer.js +79 -0
  10. package/dist/cjs/initializers/DomParserInitializer.js.map +7 -0
  11. package/dist/cjs/initializers/LinkedomInitializer.js +81 -0
  12. package/dist/cjs/initializers/LinkedomInitializer.js.map +7 -0
  13. package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js +85 -73
  14. package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js.map +2 -2
  15. package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js +2 -77
  16. package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js.map +2 -2
  17. package/dist/esm/filters/IntentSchemeFilter.js.map +2 -2
  18. package/dist/esm/filters/SSRDomParserFilter.js +163 -0
  19. package/dist/esm/filters/SSRDomParserFilter.js.map +7 -0
  20. package/dist/esm/filters/SSRFilter.js +1 -1
  21. package/dist/esm/filters/SSRFilter.js.map +2 -2
  22. package/dist/esm/filters/SSRLinkDomDomFilter.js +160 -0
  23. package/dist/esm/filters/SSRLinkDomDomFilter.js.map +7 -0
  24. package/dist/esm/initializers/DomParserInitializer.js +46 -0
  25. package/dist/esm/initializers/DomParserInitializer.js.map +7 -0
  26. package/dist/esm/initializers/LinkedomInitializer.js +48 -0
  27. package/dist/esm/initializers/LinkedomInitializer.js.map +7 -0
  28. package/dist/esm/proxy/SymbolIntentApiServiceProxy.js +85 -73
  29. package/dist/esm/proxy/SymbolIntentApiServiceProxy.js.map +2 -2
  30. package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js +2 -77
  31. package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js.map +2 -2
  32. package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js +1184 -525
  33. package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js.map +4 -4
  34. package/dist/types/filters/IntentSchemeFilter.d.ts.map +1 -1
  35. package/dist/types/filters/SSRDomParserFilter.d.ts +57 -0
  36. package/dist/types/filters/SSRDomParserFilter.d.ts.map +1 -0
  37. package/dist/types/filters/SSRLinkDomDomFilter.d.ts +57 -0
  38. package/dist/types/filters/SSRLinkDomDomFilter.d.ts.map +1 -0
  39. package/dist/types/index.d.ts +0 -19
  40. package/dist/types/initializers/DomParserInitializer.d.ts +11 -0
  41. package/dist/types/initializers/DomParserInitializer.d.ts.map +1 -0
  42. package/dist/types/initializers/LinkedomInitializer.d.ts +11 -0
  43. package/dist/types/initializers/LinkedomInitializer.d.ts.map +1 -0
  44. package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts +2 -0
  45. package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts.map +1 -1
  46. package/dist/types/proxy/SymbolIntentApiServiceProxyBase.d.ts +0 -8
  47. package/dist/types/proxy/SymbolIntentApiServiceProxyBase.d.ts.map +1 -1
  48. package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js +1184 -525
  49. package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js.map +4 -4
  50. package/package.json +16 -14
  51. package/src/filters/IntentSchemeFilter.ts +51 -48
  52. package/src/filters/SSRDomParserFilter.ts +233 -0
  53. package/src/filters/SSRFilter.ts +2 -2
  54. package/src/filters/SSRLinkDomDomFilter.ts +227 -0
  55. package/src/initializers/DomParserInitializer.ts +70 -0
  56. package/src/initializers/LinkedomInitializer.ts +69 -0
  57. package/src/proxy/SymbolIntentApiServiceProxy.ts +100 -116
  58. package/src/proxy/SymbolIntentApiServiceProxyBase.ts +7 -85
  59. package/tsconfig.json +2 -1
@@ -0,0 +1,163 @@
1
+ import { HttpHeaders } from "@dooboostore/simple-boot-http-server/codes/HttpHeaders";
2
+ import { Mimes } from "@dooboostore/simple-boot-http-server/codes/Mimes";
3
+ import { HttpStatus } from "@dooboostore/simple-boot-http-server/codes/HttpStatus";
4
+ import { AsyncBlockingQueue } from "@dooboostore/core/queues/AsyncBlockingQueue";
5
+ import { RandomUtils } from "@dooboostore/core/random/RandomUtils";
6
+ import { NotFoundError } from "@dooboostore/simple-boot-http-server/errors/NotFoundError";
7
+ import { DomRenderProxy } from "@dooboostore/dom-render/DomRenderProxy";
8
+ import { filter } from "@dooboostore/core/message/operators/filter";
9
+ import { first } from "@dooboostore/core/message/operators/first";
10
+ import { firstValueFrom } from "@dooboostore/core/message/internal/firstValueFrom";
11
+ import { Promises } from "@dooboostore/core/promise/Promises";
12
+ import { DomParserInitializer } from "../initializers/DomParserInitializer.js";
13
+ class SSRDomParserFilter {
14
+ constructor(config, otherInstanceSim) {
15
+ this.config = config;
16
+ this.otherInstanceSim = otherInstanceSim;
17
+ this.simpleBootFrontPool = [];
18
+ this.simpleBootFrontQueue = new AsyncBlockingQueue();
19
+ // private indexHTML: string;
20
+ this.welcomUrl = "http://localhost";
21
+ this.poolGeneration = 0;
22
+ config.frontDistIndexFileName = config.frontDistIndexFileName || "index.html";
23
+ }
24
+ async onInit(app) {
25
+ for (let i = 0; i < this.config.poolOption.min; i++) {
26
+ await this.pushQueue();
27
+ }
28
+ if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {
29
+ this.intervalId = setInterval(() => {
30
+ this.poolGeneration++;
31
+ }, this.config.poolOption.clearIntervalTime);
32
+ }
33
+ }
34
+ async onDestroy() {
35
+ if (this.intervalId) {
36
+ clearInterval(this.intervalId);
37
+ }
38
+ this.simpleBootFrontPool.forEach((front) => {
39
+ front.jsdom?.window.close();
40
+ });
41
+ this.simpleBootFrontPool = [];
42
+ }
43
+ async makePage() {
44
+ let windowPromise = await new DomParserInitializer(
45
+ this.config.frontDistPath,
46
+ this.config.frontDistIndexFileName || "index.html",
47
+ { url: this.welcomUrl }
48
+ ).run();
49
+ return windowPromise;
50
+ }
51
+ async makeFront(window) {
52
+ const name = RandomUtils.uuid();
53
+ window.ssrUse = false;
54
+ const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));
55
+ const simpleBootFront = await this.config.factory.create(option, this.config.using, this.config.domExcludes);
56
+ simpleBootFront.run(this.otherInstanceSim);
57
+ simpleBootFront.generation = this.poolGeneration;
58
+ return simpleBootFront;
59
+ }
60
+ enqueueFrontApp(simpleBootFront) {
61
+ this.simpleBootFrontPool.push(simpleBootFront);
62
+ this.simpleBootFrontQueue.enqueue(simpleBootFront);
63
+ }
64
+ async pushQueue() {
65
+ if (this.simpleBootFrontPool.length < this.config.poolOption.max) {
66
+ this.enqueueFrontApp(await this.makeFront(await this.makePage()));
67
+ }
68
+ }
69
+ async proceedBefore({ rr, app }) {
70
+ if (this.config.ssrExcludeFilter?.(rr)) {
71
+ return false;
72
+ }
73
+ if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {
74
+ if (this.simpleBootFrontQueue.isEmpty()) {
75
+ await this.pushQueue();
76
+ }
77
+ const simpleBootFront = await this.simpleBootFrontQueue.dequeue();
78
+ try {
79
+ simpleBootFront.option.window.ssrUse = true;
80
+ delete simpleBootFront.option.window.server_side_data;
81
+ const url = rr.reqUrlObj({ host: "localhost" });
82
+ if (this.config.simpleBootFront?.notFoundError) {
83
+ const intent = await simpleBootFront.getIntent(url.pathname);
84
+ if (intent.module === void 0 && !intent.getRouterPathData(rr.reqUrlPathName)) {
85
+ throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });
86
+ }
87
+ }
88
+ const targetUrl = url.toString();
89
+ await simpleBootFront.goRouting(targetUrl);
90
+ await Promises.sleep(0);
91
+ const data = await firstValueFrom(
92
+ simpleBootFront.routingSubjectObservable.pipe(
93
+ filter(
94
+ (it) => it.triggerPoint === "end" && typeof it.routerModule.intent.uri === "string" && targetUrl.endsWith(it.routerModule.intent.uri)
95
+ ),
96
+ // delay(1000),
97
+ first()
98
+ )
99
+ );
100
+ await Promises.sleep(0);
101
+ const html = this.makeHTML(simpleBootFront);
102
+ await this.writeOkHtmlAndEnd({ rr }, html);
103
+ } finally {
104
+ simpleBootFront.option.window.ssrUse = false;
105
+ delete simpleBootFront.option.window.server_side_data;
106
+ if (simpleBootFront.generation < this.poolGeneration) {
107
+ const jsdom = simpleBootFront.jsdom;
108
+ jsdom?.window.close();
109
+ const index = this.simpleBootFrontPool.indexOf(simpleBootFront);
110
+ if (index > -1) {
111
+ this.simpleBootFrontPool.splice(index, 1);
112
+ }
113
+ this.pushQueue();
114
+ } else {
115
+ this.simpleBootFrontQueue.enqueue(simpleBootFront);
116
+ }
117
+ }
118
+ return false;
119
+ } else {
120
+ return true;
121
+ }
122
+ }
123
+ makeHTML(simpleBootFront) {
124
+ simpleBootFront.option.window.document.querySelectorAll("*").forEach((el) => {
125
+ Array.from(el.attributes).forEach((attr) => {
126
+ if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {
127
+ el.removeAttribute(attr.name);
128
+ }
129
+ });
130
+ });
131
+ let html = simpleBootFront.option.window.document.documentElement.outerHTML;
132
+ if (!/^<!DOCTYPE html>/i.test(html)) {
133
+ html = "<!DOCTYPE html>" + html;
134
+ }
135
+ html = html.replace(/\$\{[\s\S]*?\}\$/g, "");
136
+ const serverSideData = simpleBootFront.option.window.server_side_data;
137
+ if (serverSideData) {
138
+ const data = Object.entries(serverSideData).map(([k, v]) => {
139
+ if (typeof v === "string") {
140
+ return `window.server_side_data.${k} = ${v}`;
141
+ } else {
142
+ return `window.server_side_data.${k} = ${JSON.stringify(v)}`;
143
+ }
144
+ }).join(";");
145
+ if (data) {
146
+ html = html.replace("</head>", `<script> window.server_side_data={}; ${data}; </script></head>`);
147
+ }
148
+ }
149
+ return html;
150
+ }
151
+ async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }, html) {
152
+ rr.resStatusCode(status);
153
+ rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);
154
+ await rr.resEnd(html);
155
+ }
156
+ async proceedAfter({ rr, app }) {
157
+ return true;
158
+ }
159
+ }
160
+ export {
161
+ SSRDomParserFilter
162
+ };
163
+ //# sourceMappingURL=SSRDomParserFilter.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 } from '@dooboostore/core/types';\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 { AsyncBlockingQueue } from '@dooboostore/core/queues/AsyncBlockingQueue';\nimport { RandomUtils } from '@dooboostore/core/random/RandomUtils';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render/DomRenderProxy';\nimport { filter } from '@dooboostore/core/message/operators/filter';\nimport { first } from '@dooboostore/core/message/operators/first';\nimport { delay } from '@dooboostore/core/message/operators/delay';\nimport { firstValueFrom } from '@dooboostore/core/message/internal/firstValueFrom';\nimport { parseHTML } from 'linkedom';\nimport {Promises} from '@dooboostore/core/promise/Promises';\nimport { DomParserInitializer } from '../initializers/DomParserInitializer';\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>, 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 let windowPromise = await new DomParserInitializer(\n this.config.frontDistPath,\n this.config.frontDistIndexFileName || 'index.html',\n { url: this.welcomUrl }\n ).run();\n return windowPromise;\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.getIntent(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('runRoutingrunRouting', targetUrl);\n await simpleBootFront.goRouting(targetUrl);\n await Promises.sleep(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 // console.log('runRout22222ingrunRouting', targetUrl);\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 simpleBootFront.routingSubjectObservable.pipe(\n 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 await Promises.sleep(0)\n const html = this.makeHTML(simpleBootFront);\n // console.log('---------',html);\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 if (!/^<!DOCTYPE html>/i.test(html)) {\n html = '<!DOCTYPE html>' + html;\n }\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": "AACA,SAAS,mBAAmB;AAI5B,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAI3B,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAE5B,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,aAAa;AAEtB,SAAS,sBAAsB;AAE/B,SAAQ,gBAAe;AACvB,SAAS,4BAA4B;AAoB9B,MAAM,mBAAqC;AAAA,EAQhD,YACS,QACA,kBACP;AAFO;AACA;AATT,SAAQ,sBAAyC,CAAC;AAClD,SAAQ,uBAAuB,IAAI,mBAAoC;AAEvE;AAAA,SAAQ,YAAY;AACpB,SAAQ,iBAAiB;AAOvB,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AAO,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,WAAW,GAAG,GAAiD,MAAc;AAClH,OAAG,cAAc,MAAM;AACvB,OAAG,aAAa,YAAY,aAAa,MAAM,QAAQ;AACvD,UAAM,GAAG,OAAO,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,aAAa,EAAE,IAAI,IAAI,GAAkF;AAC7G,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }
@@ -106,7 +106,7 @@ class SSRFilter {
106
106
  simpleBootFront.routingSubjectObservable.pipe(
107
107
  // @ts-ignore
108
108
  filter(
109
- (it) => it.state === "end" && typeof it.routerModule.intent.uri === "string" && targetUrl.endsWith(it.routerModule.intent.uri)
109
+ (it) => it.triggerPoint === "end" && typeof it.routerModule.intent.uri === "string" && targetUrl.endsWith(it.routerModule.intent.uri)
110
110
  ),
111
111
  // delay(1000),
112
112
  first()
@@ -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 } from '@dooboostore/core/types';\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 { AsyncBlockingQueue } from '@dooboostore/core/queues/AsyncBlockingQueue';\nimport { RandomUtils } from '@dooboostore/core/random/RandomUtils';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render/DomRenderProxy';\nimport { filter } from '@dooboostore/core/message/operators/filter';\nimport { first } from '@dooboostore/core/message/operators/first';\nimport { firstValueFrom } from '@dooboostore/core/message/internal/firstValueFrom';\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.getIntent(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.routingSubjectObservable.pipe(\n // @ts-ignore\n filter(\n (it: any) =>\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 );\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": "AACA,SAAS,mBAAmB;AAG5B,SAAS,wBAAwB;AAEjC,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAI3B,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAE5B,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAoBxB,MAAM,UAA4B;AAAA,EAQvC,YACS,QACA,kBAC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ACD,QAAI,OAAO,gBAAgB,OAAO,OAAO,SAAS,gBAAgB;AAClE,WAAO,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,WAAW,GAAG,GAAiD,MAAc;AAElH,OAAG,cAAc,MAAM;AACvB,OAAG,aAAa,YAAY,aAAa,MAAM,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 } from '@dooboostore/core/types';\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 { AsyncBlockingQueue } from '@dooboostore/core/queues/AsyncBlockingQueue';\nimport { RandomUtils } from '@dooboostore/core/random/RandomUtils';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render/DomRenderProxy';\nimport { filter } from '@dooboostore/core/message/operators/filter';\nimport { first } from '@dooboostore/core/message/operators/first';\nimport { firstValueFrom } from '@dooboostore/core/message/internal/firstValueFrom';\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.getIntent(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.routingSubjectObservable.pipe(\n // @ts-ignore\n 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": "AACA,SAAS,mBAAmB;AAG5B,SAAS,wBAAwB;AAEjC,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAI3B,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAE5B,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAoBxB,MAAM,UAA4B;AAAA,EAQvC,YACS,QACA,kBACP;AAFO;AACA;AATT,SAAQ,sBAAyC,CAAC;AAClD,SAAQ,uBAAuB,IAAI,mBAAoC;A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C3B,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,WAAW,GAAG,GAAiD,MAAc;AAElH,OAAG,cAAc,MAAM;AACvB,OAAG,aAAa,YAAY,aAAa,MAAM,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
  }
@@ -0,0 +1,160 @@
1
+ import { HttpHeaders } from "@dooboostore/simple-boot-http-server/codes/HttpHeaders";
2
+ import { Mimes } from "@dooboostore/simple-boot-http-server/codes/Mimes";
3
+ import { HttpStatus } from "@dooboostore/simple-boot-http-server/codes/HttpStatus";
4
+ import { AsyncBlockingQueue } from "@dooboostore/core/queues/AsyncBlockingQueue";
5
+ import { RandomUtils } from "@dooboostore/core/random/RandomUtils";
6
+ import { NotFoundError } from "@dooboostore/simple-boot-http-server/errors/NotFoundError";
7
+ import { DomRenderProxy } from "@dooboostore/dom-render/DomRenderProxy";
8
+ import { filter } from "@dooboostore/core/message/operators/filter";
9
+ import { first } from "@dooboostore/core/message/operators/first";
10
+ import { firstValueFrom } from "@dooboostore/core/message/internal/firstValueFrom";
11
+ import { LinkedomInitializer } from "../initializers/LinkedomInitializer.js";
12
+ class SSRLinkDomDomFilter {
13
+ constructor(config, otherInstanceSim) {
14
+ this.config = config;
15
+ this.otherInstanceSim = otherInstanceSim;
16
+ this.simpleBootFrontPool = [];
17
+ this.simpleBootFrontQueue = new AsyncBlockingQueue();
18
+ // private indexHTML: string;
19
+ this.welcomUrl = "http://localhost";
20
+ this.poolGeneration = 0;
21
+ config.frontDistIndexFileName = config.frontDistIndexFileName || "index.html";
22
+ }
23
+ async onInit(app) {
24
+ for (let i = 0; i < this.config.poolOption.min; i++) {
25
+ await this.pushQueue();
26
+ }
27
+ if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {
28
+ this.intervalId = setInterval(() => {
29
+ this.poolGeneration++;
30
+ }, this.config.poolOption.clearIntervalTime);
31
+ }
32
+ }
33
+ async onDestroy() {
34
+ if (this.intervalId) {
35
+ clearInterval(this.intervalId);
36
+ }
37
+ this.simpleBootFrontPool.forEach((front) => {
38
+ front.jsdom?.window.close();
39
+ });
40
+ this.simpleBootFrontPool = [];
41
+ }
42
+ async makePage() {
43
+ return new LinkedomInitializer(
44
+ this.config.frontDistPath,
45
+ this.config.frontDistIndexFileName || "index.html",
46
+ { url: this.welcomUrl }
47
+ ).run();
48
+ }
49
+ async makeFront(window) {
50
+ const name = RandomUtils.uuid();
51
+ window.ssrUse = false;
52
+ const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));
53
+ const simpleBootFront = await this.config.factory.create(option, this.config.using, this.config.domExcludes);
54
+ simpleBootFront.run(this.otherInstanceSim);
55
+ simpleBootFront.generation = this.poolGeneration;
56
+ return simpleBootFront;
57
+ }
58
+ enqueueFrontApp(simpleBootFront) {
59
+ this.simpleBootFrontPool.push(simpleBootFront);
60
+ this.simpleBootFrontQueue.enqueue(simpleBootFront);
61
+ }
62
+ async pushQueue() {
63
+ if (this.simpleBootFrontPool.length < this.config.poolOption.max) {
64
+ this.enqueueFrontApp(await this.makeFront(await this.makePage()));
65
+ }
66
+ }
67
+ async proceedBefore({ rr, app }) {
68
+ if (this.config.ssrExcludeFilter?.(rr)) {
69
+ return false;
70
+ }
71
+ if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {
72
+ if (this.simpleBootFrontQueue.isEmpty()) {
73
+ await this.pushQueue();
74
+ }
75
+ const simpleBootFront = await this.simpleBootFrontQueue.dequeue();
76
+ try {
77
+ simpleBootFront.option.window.ssrUse = true;
78
+ delete simpleBootFront.option.window.server_side_data;
79
+ const url = rr.reqUrlObj({ host: "localhost" });
80
+ if (this.config.simpleBootFront?.notFoundError) {
81
+ const intent = await simpleBootFront.getIntent(url.pathname);
82
+ if (intent.module === void 0 && !intent.getRouterPathData(rr.reqUrlPathName)) {
83
+ throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });
84
+ }
85
+ }
86
+ const targetUrl = url.toString();
87
+ await simpleBootFront.goRouting(targetUrl);
88
+ await new Promise((r) => setTimeout(r, 0));
89
+ const data = await firstValueFrom(
90
+ // @ts-ignore
91
+ simpleBootFront.routingSubjectObservable.pipe(
92
+ // @ts-ignore
93
+ filter(
94
+ (it) => it.triggerPoint === "end" && typeof it.routerModule.intent.uri === "string" && targetUrl.endsWith(it.routerModule.intent.uri)
95
+ ),
96
+ // delay(1000),
97
+ first()
98
+ )
99
+ );
100
+ const html = this.makeHTML(simpleBootFront);
101
+ await this.writeOkHtmlAndEnd({ rr }, html);
102
+ } finally {
103
+ simpleBootFront.option.window.ssrUse = false;
104
+ delete simpleBootFront.option.window.server_side_data;
105
+ if (simpleBootFront.generation < this.poolGeneration) {
106
+ const jsdom = simpleBootFront.jsdom;
107
+ jsdom?.window.close();
108
+ const index = this.simpleBootFrontPool.indexOf(simpleBootFront);
109
+ if (index > -1) {
110
+ this.simpleBootFrontPool.splice(index, 1);
111
+ }
112
+ this.pushQueue();
113
+ } else {
114
+ this.simpleBootFrontQueue.enqueue(simpleBootFront);
115
+ }
116
+ }
117
+ return false;
118
+ } else {
119
+ return true;
120
+ }
121
+ }
122
+ makeHTML(simpleBootFront) {
123
+ simpleBootFront.option.window.document.querySelectorAll("*").forEach((el) => {
124
+ Array.from(el.attributes).forEach((attr) => {
125
+ if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {
126
+ el.removeAttribute(attr.name);
127
+ }
128
+ });
129
+ });
130
+ let html = simpleBootFront.option.window.document.documentElement.outerHTML;
131
+ html = "<!DOCTYPE html>" + html;
132
+ html = html.replace(/\$\{[\s\S]*?\}\$/g, "");
133
+ const serverSideData = simpleBootFront.option.window.server_side_data;
134
+ if (serverSideData) {
135
+ const data = Object.entries(serverSideData).map(([k, v]) => {
136
+ if (typeof v === "string") {
137
+ return `window.server_side_data.${k} = ${v}`;
138
+ } else {
139
+ return `window.server_side_data.${k} = ${JSON.stringify(v)}`;
140
+ }
141
+ }).join(";");
142
+ if (data) {
143
+ html = html.replace("</head>", `<script> window.server_side_data={}; ${data}; </script></head>`);
144
+ }
145
+ }
146
+ return html;
147
+ }
148
+ async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }, html) {
149
+ rr.resStatusCode(status);
150
+ rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);
151
+ await rr.resEnd(html);
152
+ }
153
+ async proceedAfter({ rr, app }) {
154
+ return true;
155
+ }
156
+ }
157
+ export {
158
+ SSRLinkDomDomFilter
159
+ };
160
+ //# sourceMappingURL=SSRLinkDomDomFilter.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/filters/SSRLinkDomDomFilter.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 } from '@dooboostore/core/types';\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 { AsyncBlockingQueue } from '@dooboostore/core/queues/AsyncBlockingQueue';\nimport { RandomUtils } from '@dooboostore/core/random/RandomUtils';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render/DomRenderProxy';\nimport { filter } from '@dooboostore/core/message/operators/filter';\nimport { first } from '@dooboostore/core/message/operators/first';\nimport { firstValueFrom } from '@dooboostore/core/message/internal/firstValueFrom';\nimport { parseHTML } from 'linkedom';\nimport { LinkedomInitializer } from '../initializers/LinkedomInitializer';\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 SSRLinkDomDomFilter 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 }\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.getIntent(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.routingSubjectObservable.pipe(\n // @ts-ignore\n 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}\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IAAI;AAAA,QAC9B;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AACD,QAAI,OAAO,gBAAgB,OAAO,OAAO,SAAS,gBAAgB;AAClE,WAAO,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,WAAW,GAAG,GAAiD,MAAc;AAClH,OAAG,cAAc,MAAM;AACvB,OAAG,aAAa,YAAY,aAAa,MAAM,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,46 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { parseHTML } from "@dooboostore/dom-parser";
4
+ class DomParserInitializer {
5
+ constructor(frontDistPath, frontDistIndexFileName, reconfigureSettings) {
6
+ this.frontDistPath = frontDistPath;
7
+ this.frontDistIndexFileName = frontDistIndexFileName;
8
+ this.reconfigureSettings = reconfigureSettings;
9
+ }
10
+ static loadFile(distPath, filePath) {
11
+ return fs.readFileSync(path.join(distPath, filePath), "utf8");
12
+ }
13
+ async run() {
14
+ const pathStr = path.join(this.frontDistPath, this.frontDistIndexFileName);
15
+ const html = fs.readFileSync(pathStr, "utf8");
16
+ const w = parseHTML(html, { href: this.reconfigureSettings.url });
17
+ ;
18
+ w.location ??= { href: "about:blank" };
19
+ if (this.reconfigureSettings?.url) {
20
+ w.location.href = this.reconfigureSettings.url;
21
+ }
22
+ global.Event = w.Event;
23
+ global.PopStateEvent = w.Event;
24
+ global.IntersectionObserver = w.IntersectionObserver;
25
+ global.NodeFilter = w.NodeFilter;
26
+ global.Node = w.Node;
27
+ global.DocumentFragment = w.DocumentFragment;
28
+ global.HTMLElement = w.HTMLElement;
29
+ global.HTMLMetaElement = w.HTMLMetaElement;
30
+ global.Element = w.Element;
31
+ global.HTMLCanvasElement = w.HTMLCanvasElement;
32
+ global.HTMLCanvasElement.prototype.getContext = () => {
33
+ return null;
34
+ };
35
+ global.CanvasRenderingContext2D = w.CanvasRenderingContext2D;
36
+ global.CanvasPattern = w.CanvasPattern;
37
+ global.CanvasGradient = w.CanvasGradient;
38
+ global.Path2D = w.Path2D;
39
+ global.ImageData = w.ImageData;
40
+ return w;
41
+ }
42
+ }
43
+ export {
44
+ DomParserInitializer
45
+ };
46
+ //# sourceMappingURL=DomParserInitializer.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/initializers/DomParserInitializer.ts"],
4
+ "sourcesContent": ["import fs from 'fs';\nimport path from 'path';\nimport { parseHTML } from '@dooboostore/dom-parser';\n\nexport class DomParserInitializer {\n constructor(\n private frontDistPath: string,\n private frontDistIndexFileName: string,\n private reconfigureSettings?: {url: string}\n ) {}\n\n public static loadFile(distPath: string, filePath: string): string {\n return fs.readFileSync(path.join(distPath, filePath), 'utf8');\n }\n\n async run(): Promise<Window> {\n // const indexHTML = fs.readFileSync(path.join(this.frontDistPath, 'index.html'), 'utf8');\n // const indexHTML = JsdomInitializer.loadFile(this.frontDistPath, this.frontDistIndexFileName);\n const pathStr = path.join(this.frontDistPath, this.frontDistIndexFileName);\n\n const html = fs.readFileSync(pathStr,'utf8');\n\n const w = parseHTML(html, {href: this.reconfigureSettings.url}) as unknown as Window & typeof globalThis; ;\n\n // @ts-ignore\n w.location ??= { href: 'about:blank'};\n if(this.reconfigureSettings?.url){\n // console.log('--',w,w.location);\n // @ts-ignore\n w.location.href = this.reconfigureSettings.url;\n }\n // console.log('!!!!!!!!!!!', html, w.document);\n // @ts-ignore\n // global.document = w.document;\n // @ts-ignore\n // global.window = w as unknown as Window & typeof globalThis;\n // @ts-ignore\n // global.window.requestAnimationFrame = () => {};\n // global.window.scrollTo = () => {};\n // @ts-ignore\n // global.history = w.history;\n global.Event = w.Event;\n // @ts-ignore\n global.PopStateEvent = w.Event;\n global.IntersectionObserver = w.IntersectionObserver;\n // @ts-ignore\n // global.Error = ErrorBase;\n // @ts-ignore\n // global.navigator = w.navigator;\n global.NodeFilter = w.NodeFilter;\n global.Node = w.Node;\n global.DocumentFragment = w.DocumentFragment;\n global.HTMLElement = w.HTMLElement;\n global.HTMLMetaElement = w.HTMLMetaElement;\n global.Element = w.Element;\n global.HTMLCanvasElement = w.HTMLCanvasElement;\n global.HTMLCanvasElement.prototype.getContext = () => {\n return null;\n };\n global.CanvasRenderingContext2D = w.CanvasRenderingContext2D;\n global.CanvasPattern = w.CanvasPattern;\n global.CanvasGradient = w.CanvasGradient;\n global.Path2D = w.Path2D;\n global.ImageData = w.ImageData;\n // console.log('cvvvvvvvvvvvvvv', w.Node.DOCUMENT_FRAGMENT_NODE);\n return w;\n }\n}\n//\n// export default new JsdomInitializer();\n"],
5
+ "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAEnB,MAAM,qBAAqB;AAAA,EAChC,YACU,eACA,wBACA,qBACR;AAHQ;AACA;AACA;AAAA,EACP;AAAA,EAEH,OAAc,SAAS,UAAkB,UAA0B;AACjE,WAAO,GAAG,aAAa,KAAK,KAAK,UAAU,QAAQ,GAAG,MAAM;AAAA,EAC9D;AAAA,EAEA,MAAM,MAAuB;AAG3B,UAAM,UAAU,KAAK,KAAK,KAAK,eAAe,KAAK,sBAAsB;AAEzE,UAAM,OAAO,GAAG,aAAa,SAAQ,MAAM;AAE3C,UAAM,IAAI,UAAU,MAAM,EAAC,MAAM,KAAK,oBAAoB,IAAG,CAAC;AAA4C;AAG1G,MAAE,aAAa,EAAE,MAAM,cAAa;AACpC,QAAG,KAAK,qBAAqB,KAAI;AAG/B,QAAE,SAAS,OAAO,KAAK,oBAAoB;AAAA,IAC7C;AAWA,WAAO,QAAQ,EAAE;AAEjB,WAAO,gBAAgB,EAAE;AACzB,WAAO,uBAAuB,EAAE;AAKhC,WAAO,aAAa,EAAE;AACtB,WAAO,OAAO,EAAE;AAChB,WAAO,mBAAmB,EAAE;AAC5B,WAAO,cAAc,EAAE;AACvB,WAAO,kBAAkB,EAAE;AAC3B,WAAO,UAAU,EAAE;AACnB,WAAO,oBAAoB,EAAE;AAC7B,WAAO,kBAAkB,UAAU,aAAa,MAAM;AACpD,aAAO;AAAA,IACT;AACA,WAAO,2BAA2B,EAAE;AACpC,WAAO,gBAAgB,EAAE;AACzB,WAAO,iBAAiB,EAAE;AAC1B,WAAO,SAAS,EAAE;AAClB,WAAO,YAAY,EAAE;AAErB,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,48 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { parseHTML } from "linkedom";
4
+ class LinkedomInitializer {
5
+ constructor(frontDistPath, frontDistIndexFileName, reconfigureSettings) {
6
+ this.frontDistPath = frontDistPath;
7
+ this.frontDistIndexFileName = frontDistIndexFileName;
8
+ this.reconfigureSettings = reconfigureSettings;
9
+ }
10
+ static loadFile(distPath, filePath) {
11
+ return fs.readFileSync(path.join(distPath, filePath), "utf8");
12
+ }
13
+ async run() {
14
+ const pathStr = path.join(this.frontDistPath, this.frontDistIndexFileName);
15
+ const html = fs.readFileSync(pathStr, "utf8");
16
+ const w = parseHTML(html);
17
+ global.document = w.document;
18
+ global.window = w;
19
+ global.window.requestAnimationFrame = () => {
20
+ };
21
+ global.window.scrollTo = () => {
22
+ };
23
+ global.history = w.history;
24
+ global.Event = w.Event;
25
+ global.PopStateEvent = w.Event;
26
+ global.IntersectionObserver = w.IntersectionObserver;
27
+ global.NodeFilter = w.NodeFilter;
28
+ global.Node = w.Node;
29
+ global.DocumentFragment = w.DocumentFragment;
30
+ global.HTMLElement = w.HTMLElement;
31
+ global.HTMLMetaElement = w.HTMLMetaElement;
32
+ global.Element = w.Element;
33
+ global.HTMLCanvasElement = w.HTMLCanvasElement;
34
+ global.HTMLCanvasElement.prototype.getContext = () => {
35
+ return null;
36
+ };
37
+ global.CanvasRenderingContext2D = w.CanvasRenderingContext2D;
38
+ global.CanvasPattern = w.CanvasPattern;
39
+ global.CanvasGradient = w.CanvasGradient;
40
+ global.Path2D = w.Path2D;
41
+ global.ImageData = w.ImageData;
42
+ return w;
43
+ }
44
+ }
45
+ export {
46
+ LinkedomInitializer
47
+ };
48
+ //# sourceMappingURL=LinkedomInitializer.js.map