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

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 (83) hide show
  1. package/README.md +98 -0
  2. package/dist/cjs/SimpleBootHttpSSRServer.js.map +2 -2
  3. package/dist/cjs/bundle-entry.js +0 -2
  4. package/dist/cjs/bundle-entry.js.map +2 -2
  5. package/dist/cjs/filters/SSRDomParserFilter.js.map +2 -2
  6. package/dist/cjs/filters/{SSRLinkDomDomFilter.js → SSRLinkDomFilter.js} +7 -7
  7. package/dist/cjs/filters/SSRLinkDomFilter.js.map +7 -0
  8. package/dist/cjs/filters/SSRSimpleWebComponentDomParserFilter.js +81 -0
  9. package/dist/cjs/filters/SSRSimpleWebComponentDomParserFilter.js.map +7 -0
  10. package/dist/cjs/filters/SSRSimpleWebComponentFilter.js +158 -28
  11. package/dist/cjs/filters/SSRSimpleWebComponentFilter.js.map +2 -2
  12. package/dist/cjs/filters/index.js +9 -3
  13. package/dist/cjs/filters/index.js.map +2 -2
  14. package/dist/cjs/index.js +0 -2
  15. package/dist/cjs/index.js.map +2 -2
  16. package/dist/esm/SimpleBootHttpSSRServer.js.map +2 -2
  17. package/dist/esm/bundle-entry.js +0 -1
  18. package/dist/esm/bundle-entry.js.map +2 -2
  19. package/dist/esm/filters/SSRDomParserFilter.js.map +2 -2
  20. package/dist/esm/filters/{SSRLinkDomDomFilter.js → SSRLinkDomFilter.js} +3 -3
  21. package/dist/esm/filters/SSRLinkDomFilter.js.map +7 -0
  22. package/dist/esm/filters/SSRSimpleWebComponentDomParserFilter.js +58 -0
  23. package/dist/esm/filters/SSRSimpleWebComponentDomParserFilter.js.map +7 -0
  24. package/dist/esm/filters/SSRSimpleWebComponentFilter.js +148 -28
  25. package/dist/esm/filters/SSRSimpleWebComponentFilter.js.map +2 -2
  26. package/dist/esm/filters/index.js +4 -1
  27. package/dist/esm/filters/index.js.map +2 -2
  28. package/dist/esm/index.js +0 -1
  29. package/dist/esm/index.js.map +2 -2
  30. package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js +54537 -21104
  31. package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js.map +4 -4
  32. package/dist/types/SimpleBootHttpSSRServer.d.ts +1 -1
  33. package/dist/types/SimpleBootHttpSSRServer.d.ts.map +1 -1
  34. package/dist/types/bundle-entry.d.ts +0 -1
  35. package/dist/types/bundle-entry.d.ts.map +1 -1
  36. package/dist/types/filters/SSRDomParserFilter.d.ts +3 -3
  37. package/dist/types/filters/SSRDomParserFilter.d.ts.map +1 -1
  38. package/dist/types/filters/{SSRLinkDomDomFilter.d.ts → SSRLinkDomFilter.d.ts} +5 -5
  39. package/dist/types/filters/SSRLinkDomFilter.d.ts.map +1 -0
  40. package/dist/types/filters/SSRSimpleWebComponentDomParserFilter.d.ts +37 -0
  41. package/dist/types/filters/SSRSimpleWebComponentDomParserFilter.d.ts.map +1 -0
  42. package/dist/types/filters/SSRSimpleWebComponentFilter.d.ts +23 -3
  43. package/dist/types/filters/SSRSimpleWebComponentFilter.d.ts.map +1 -1
  44. package/dist/types/filters/index.d.ts +4 -1
  45. package/dist/types/filters/index.d.ts.map +1 -1
  46. package/dist/types/index.d.ts +0 -1
  47. package/dist/types/index.d.ts.map +1 -1
  48. package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js +54592 -21160
  49. package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js.map +4 -4
  50. package/package.json +17 -16
  51. package/src/SimpleBootHttpSSRServer.ts +2 -3
  52. package/src/bundle-entry.ts +0 -1
  53. package/src/filters/SSRDomParserFilter.ts +4 -4
  54. package/src/filters/{SSRLinkDomDomFilter.ts → SSRLinkDomFilter.ts} +3 -3
  55. package/src/filters/SSRSimpleWebComponentDomParserFilter.ts +106 -0
  56. package/src/filters/SSRSimpleWebComponentFilter.ts +242 -39
  57. package/src/filters/index.ts +5 -2
  58. package/src/index.ts +0 -1
  59. package/README.MD +0 -167
  60. package/dist/cjs/decorators/LoadAroundBefore.js +0 -54
  61. package/dist/cjs/decorators/LoadAroundBefore.js.map +0 -7
  62. package/dist/cjs/decorators/SaveAroundAfter.js +0 -53
  63. package/dist/cjs/decorators/SaveAroundAfter.js.map +0 -7
  64. package/dist/cjs/decorators/index.js +0 -24
  65. package/dist/cjs/decorators/index.js.map +0 -7
  66. package/dist/cjs/filters/SSRLinkDomDomFilter.js.map +0 -7
  67. package/dist/esm/decorators/LoadAroundBefore.js +0 -31
  68. package/dist/esm/decorators/LoadAroundBefore.js.map +0 -7
  69. package/dist/esm/decorators/SaveAroundAfter.js +0 -29
  70. package/dist/esm/decorators/SaveAroundAfter.js.map +0 -7
  71. package/dist/esm/decorators/index.js +0 -3
  72. package/dist/esm/decorators/index.js.map +0 -7
  73. package/dist/esm/filters/SSRLinkDomDomFilter.js.map +0 -7
  74. package/dist/types/decorators/LoadAroundBefore.d.ts +0 -2
  75. package/dist/types/decorators/LoadAroundBefore.d.ts.map +0 -1
  76. package/dist/types/decorators/SaveAroundAfter.d.ts +0 -3
  77. package/dist/types/decorators/SaveAroundAfter.d.ts.map +0 -1
  78. package/dist/types/decorators/index.d.ts +0 -3
  79. package/dist/types/decorators/index.d.ts.map +0 -1
  80. package/dist/types/filters/SSRLinkDomDomFilter.d.ts.map +0 -1
  81. package/src/decorators/LoadAroundBefore.ts +0 -28
  82. package/src/decorators/SaveAroundAfter.ts +0 -27
  83. 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
  }
@@ -14,7 +14,6 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
14
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
15
  var bundle_entry_exports = {};
16
16
  module.exports = __toCommonJS(bundle_entry_exports);
17
- __reExport(bundle_entry_exports, require("./decorators"), module.exports);
18
17
  __reExport(bundle_entry_exports, require("./filters"), module.exports);
19
18
  __reExport(bundle_entry_exports, require("./initializers"), module.exports);
20
19
  __reExport(bundle_entry_exports, require("./option"), module.exports);
@@ -23,7 +22,6 @@ __reExport(bundle_entry_exports, require("./SimpleBootHttpSSRFactory"), module.e
23
22
  __reExport(bundle_entry_exports, require("./SimpleBootHttpSSRServer"), module.exports);
24
23
  // Annotate the CommonJS export names for ESM import in node:
25
24
  0 && (module.exports = {
26
- ...require("./decorators"),
27
25
  ...require("./filters"),
28
26
  ...require("./initializers"),
29
27
  ...require("./option"),
@@ -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": ["export * from './filters';\nexport * from './initializers';\nexport * from './option';\nexport * from './proxy';\nexport * from './SimpleBootHttpSSRFactory';\nexport * from './SimpleBootHttpSSRServer';"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,iCAAc,sBAAd;AACA,iCAAc,2BADd;AAEA,iCAAc,qBAFd;AAGA,iCAAc,oBAHd;AAIA,iCAAc,uCAJd;AAKA,iCAAc,sCALd;",
6
6
  "names": []
7
7
  }
@@ -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,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,KAAK,OAAO,QAAQ,OAAO,QAAQ,KAAK,OAAO,OAAO,WAAW;AAC/F,yBAAqB,oBAAI,IAA+D;AACxF,SAAK,kBAAkB,QAAQ,CAAC,GAAG,MAAM,iBAAkB,IAAI,GAAG,CAAC,CAAC;AAEpE,oBAAgB,IAAI,gBAAgB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estResponse';\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 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 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,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,KAA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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;",
6
6
  "names": []
7
7
  }
@@ -15,11 +15,11 @@ 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
25
  var import_Mimes = require("@dooboostore/simple-boot-http-server/codes/Mimes");
@@ -27,7 +27,7 @@ var import_HttpStatus = require("@dooboostore/simple-boot-http-server/codes/Http
27
27
  var import_NotFoundError = require("@dooboostore/simple-boot-http-server/errors/NotFoundError");
28
28
  var import_dom_render = require("@dooboostore/dom-render");
29
29
  var import_LinkedomInitializer = require("../initializers/LinkedomInitializer");
30
- class SSRLinkDomDomFilter {
30
+ class SSRLinkDomFilter {
31
31
  constructor(config, otherInstanceSim) {
32
32
  this.config = config;
33
33
  this.otherInstanceSim = otherInstanceSim;
@@ -174,6 +174,6 @@ class SSRLinkDomDomFilter {
174
174
  }
175
175
  // Annotate the CommonJS export names for ESM import in node:
176
176
  0 && (module.exports = {
177
- SSRLinkDomDomFilter
177
+ SSRLinkDomFilter
178
178
  });
179
- //# sourceMappingURL=SSRLinkDomDomFilter.js.map
179
+ //# 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, 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';\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 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('???????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,kBAAmG;AAGnG,mBAAsB;AACtB,wBAA2B;AAK3B,2BAA8B;AAC9B,wBAA+B;AAE/B,iCAAoC;AAoB7B,MAAM,iBAAmC;AAAA,EAQ9C,YACS,QACA,kBACP;AAFO;AACA;AATT,SAAQ,sBAAyC,CAAC;AAClD,SAAQ,uBAAuB,IAAI,+BAAoC;AAEvE;AAAA,SAAQ,YAAY;AACpB,SAAQ,iBAAiB;AAOvB,WAAO,yBAAyB,OAAO,0BAA0B;AAAA,EAEnE;AAAA,EAEA,MAAM,OAAO,KAA2B;AACtC,aAAS,IAAI,GAAG,IAAI,KAAK,OAAO,WAAW,KAAK,KAAK;AACnD,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,QAAI,KAAK,OAAO,WAAW,qBAAqB,KAAK,OAAO,WAAW,oBAAoB,GAAG;AAC5F,WAAK,aAAa,YAAY,MAAM;AAClC,aAAK;AAAA,MACP,GAAG,KAAK,OAAO,WAAW,iBAAiB;AAAA,IAC7C;AAAA,EACF;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,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
+ const domParserInitializer = new import_DomParserInitializer.DomParserInitializer(this.config.frontDistPath, this.config.frontDistIndexFileName || "index.html", { url: targetUrl });
45
+ const window = await domParserInitializer.run();
46
+ console.log("vvvv22aa");
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
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/filters/SSRSimpleWebComponentDomParserFilter.ts"],
4
+ "sourcesContent": ["import {RequestResponse} from '@dooboostore/simple-boot-http-server/models/RequestResponse';\nimport {HttpHeaders} from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';\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 {DomParserInitializer} from '../initializers/DomParserInitializer';\n\nexport type SWCSSRDomParserConfig = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n welcomUrl?: string;\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n /**\n * Function to register components for each request.\n */\n registerComponents?: (window: any) => Promise<void> | void;\n};\n\n/**\n * SSR Filter specifically for Simple Web Component (SWC).\n * It utilizes @dooboostore/dom-parser for rendering and DSD support.\n */\nexport class SSRSimpleWebComponentDomParserFilter implements Filter {\n private welcomUrl = 'http://localhost';\n\n constructor(public config: SWCSSRDomParserConfig) {\n this.welcomUrl = config.welcomUrl || this.welcomUrl;\n }\n\n async onInit(app: SimpleBootHttpServer) {}\n\n async onDestroy() {}\n\n async proceedBefore({ rr }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return false;\n }\n\n if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {\n const url = rr.reqUrlObj({ host: 'localhost' });\n const targetUrl = url.toString() ?? this.welcomUrl;\n\n // 1. Initialize Virtual DOM Environment\n const domParserInitializer = new DomParserInitializer(this.config.frontDistPath, this.config.frontDistIndexFileName || 'index.html', { url: targetUrl });\n const window = await domParserInitializer.run();\n\n console.log('vvvv22aa');\n // web component \uACBD\uC6B0 \uC790\uAE30 tagName\uC744 \uC0DD\uC131\uC790 \uC5D0\uAC8C HTMLElementBase\uC5D0\uB118\uACA8\uC918\uC57C\uB418\uAE30\uB584\uBB38\uC5D0\n // const getTagName = (type: ConstructorType<any>) => {\n // const zz = getElementConfig(type);\n // return zz.name;\n // };\n // (window as any).HTMLElement = class extends HTMLElementBase {\n // constructor(...args: any[]) {\n // const ctor = new.target as any; // \uC774\uB7F0 \uC288\uAC00 \uAE30\uB2A5\uC774...\n // const resolvedTagName = getTagName(ctor);\n // super(resolvedTagName, args[0]);\n // }\n // }\n\n\n try {\n // 2. Register Components if provided\n // We use SwcApplication inside the callback or directly here.\n if (this.config.registerComponents) {\n await this.config.registerComponents(window);\n }\n\n // window.document.querySelector('.sidebar-space').innerHTML = '\uC528\uBC1C\uB188\uC544.';\n // await new Promise<void>((resolve, reject) => setTimeout(resolve, 100));\n // await new Promise<void>((resolve, reject) => setTimeout(resolve, 5000));\n // window.document.body.innerHTML = '';\n // window.document.body.setAttribute('ssr-use', 'true');\n // 3. Generate Final HTML\n const html = this.makeHTML(window);\n // console.log('html: \uD83D\uDC88', html);\n await this.writeOkHtmlAndEnd({ rr }, html);\n } finally {\n // 4. Cleanup\n window.close();\n domParserInitializer.destroy();\n }\n return false;\n }\n return true;\n }\n\n makeHTML(window: any) {\n let html = window.document.documentElement.outerHTML;\n if (!/^<!DOCTYPE html>/i.test(html)) {\n html = '<!DOCTYPE html>\\n' + html;\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() {\n return true;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAA0B;AAE1B,mBAAoB;AACpB,wBAAyB;AAEzB,kCAAmC;AAiB5B,MAAM,qCAAuD;AAAA,EAGlE,YAAmB,QAA+B;AAA/B;AAFnB,SAAQ,YAAY;AAGlB,SAAK,YAAY,OAAO,aAAa,KAAK;AAAA,EAC5C;AAAA,EAEA,MAAM,OAAO,KAA2B;AAAA,EAAC;AAAA,EAEzC,MAA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.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;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
  var SSRSimpleWebComponentFilter_exports = {};
19
29
  __export(SSRSimpleWebComponentFilter_exports, {
@@ -23,9 +33,7 @@ module.exports = __toCommonJS(SSRSimpleWebComponentFilter_exports);
23
33
  var import_HttpHeaders = require("@dooboostore/simple-boot-http-server/codes/HttpHeaders");
24
34
  var import_Mimes = require("@dooboostore/simple-boot-http-server/codes/Mimes");
25
35
  var import_HttpStatus = require("@dooboostore/simple-boot-http-server/codes/HttpStatus");
26
- var import_DomParserInitializer = require("../initializers/DomParserInitializer");
27
- var import_dom_parser = require("@dooboostore/dom-parser");
28
- var import_simple_web_component = require("@dooboostore/simple-web-component");
36
+ var import_simple_boot_http_server = require("@dooboostore/simple-boot-http-server");
29
37
  class SSRSimpleWebComponentFilter {
30
38
  constructor(config) {
31
39
  this.config = config;
@@ -33,45 +41,167 @@ class SSRSimpleWebComponentFilter {
33
41
  this.welcomUrl = config.welcomUrl || this.welcomUrl;
34
42
  }
35
43
  async onInit(app) {
44
+ const { chromium } = await import("playwright");
45
+ this.browser = await chromium.launch({
46
+ headless: true,
47
+ args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-web-security"]
48
+ // Allow CORS for local dev
49
+ });
50
+ console.log("\u{1F680} Playwright Browser initialized for SSR Filter");
36
51
  }
37
52
  async onDestroy() {
53
+ if (this.browser) {
54
+ await this.browser.close();
55
+ console.log("\u{1F6D1} Playwright Browser closed");
56
+ }
38
57
  }
39
- async proceedBefore({ rr }) {
58
+ async proceedBefore({ rr, app, carrier }) {
40
59
  if (this.config.ssrExcludeFilter?.(rr)) {
41
- return false;
60
+ return true;
61
+ }
62
+ console.log("playwright2222222", rr.reqHeader("x-ssr-browser"));
63
+ if (rr.reqHeader("x-ssr-browser") === "playwright") {
64
+ return true;
42
65
  }
43
- if (rr.reqHasAcceptHeader(import_Mimes.Mimes.TextHtml) || rr.reqHasAcceptHeader(import_Mimes.Mimes.All)) {
44
- const url = rr.reqUrlObj({ host: "localhost" });
66
+ if (rr.reqIsMethod(import_simple_boot_http_server.HttpMethod.GET) && rr.reqHasContentTypeHeader(import_Mimes.Mimes.TextHtml)) {
67
+ const protocol = app.option.protocol || "http";
68
+ const host = app.option.hostname || "127.0.0.1";
69
+ const port = app.option.port || 80;
70
+ const url = rr.reqUrlObj({ host: `${host}:${port}` });
71
+ url.protocol = protocol;
45
72
  const targetUrl = url.toString() ?? this.welcomUrl;
46
- const domParserInitializer = new import_DomParserInitializer.DomParserInitializer(this.config.frontDistPath, this.config.frontDistIndexFileName || "index.html", { url: targetUrl });
47
- const window = await domParserInitializer.run();
48
- const getTagName = (type) => {
49
- const zz = (0, import_simple_web_component.getElementConfig)(type);
50
- return zz.name;
51
- };
52
- window.HTMLElement = class extends import_dom_parser.HTMLElementBase {
53
- constructor(...args) {
54
- const ctor = new.target;
55
- const resolvedTagName = getTagName(ctor);
56
- super(resolvedTagName, args[0]);
57
- }
58
- };
73
+ if (!this.browser) {
74
+ console.error("Playwright browser is not initialized. Bypassing SSR.");
75
+ return true;
76
+ }
77
+ const context = await this.browser.newContext();
78
+ const page = await context.newPage();
59
79
  try {
60
- if (this.config.registerComponents) {
61
- await this.config.registerComponents(window);
80
+ await page.route("**/*", (route) => {
81
+ const request = route.request();
82
+ const isLocal = request.url().startsWith(targetUrl) || request.url().includes("localhost") || request.url().includes("127.0.0.1");
83
+ const isApi = request.url().includes("/api/");
84
+ if (isLocal && !isApi) {
85
+ const headers = {
86
+ ...request.headers(),
87
+ "x-ssr-browser": "playwright"
88
+ };
89
+ route.continue({ headers }).catch(() => {
90
+ });
91
+ } else {
92
+ route.continue().catch(() => {
93
+ });
94
+ }
95
+ });
96
+ let resolvePlaywrightReady;
97
+ const playwrightReadyPromise = new Promise((resolve) => {
98
+ resolvePlaywrightReady = resolve;
99
+ });
100
+ await page.exposeFunction("onPlaywrightReady", () => {
101
+ console.log('\u26A1\uFE0F [SSR:Playwright] Received "onPlaywrightReady" signal from framework!');
102
+ resolvePlaywrightReady();
103
+ });
104
+ await page.goto(targetUrl, {
105
+ waitUntil: this.config.playwright?.waitUntil ?? "networkidle",
106
+ timeout: this.config.playwright?.timeout ?? 15e3
107
+ });
108
+ await Promise.race([
109
+ playwrightReadyPromise,
110
+ // 직접 exposeFunction에서 트리거된 Promise
111
+ page.waitForFunction(
112
+ () => {
113
+ return window._playwrightReadySignalFired === true;
114
+ },
115
+ { timeout: this.config.playwright?.timeout ?? 15e3 }
116
+ ),
117
+ page.waitForFunction(
118
+ () => {
119
+ return document.body.innerHTML.trim().length > 100;
120
+ },
121
+ { timeout: this.config.playwright?.timeout ?? 15e3 }
122
+ )
123
+ ]).catch(() => console.log("Wait for app mount timeout... proceeding anyway"));
124
+ if (this.config.playwright?.waitForSelector) {
125
+ await page.waitForSelector(this.config.playwright.waitForSelector, {
126
+ timeout: this.config.playwright?.timeout ?? 15e3
127
+ });
128
+ }
129
+ if (this.config.playwright?.waitForTimeout) {
130
+ await page.waitForTimeout(this.config.playwright.waitForTimeout);
62
131
  }
63
- const html = this.makeHTML(window);
64
- await this.writeOkHtmlAndEnd({ rr }, html);
132
+ await page.evaluate(() => {
133
+ document.body.setAttribute("ssr-use", "true");
134
+ });
135
+ const html = await page.evaluate((ignoreTags) => {
136
+ const skipTags = new Set(ignoreTags || []);
137
+ function serializeNode(node, inBody = false) {
138
+ if (node.nodeType === Node.TEXT_NODE) {
139
+ const text = node.textContent || "";
140
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
141
+ }
142
+ if (node.nodeType === Node.COMMENT_NODE) {
143
+ return `<!--${node.textContent}-->`;
144
+ }
145
+ if (node.nodeType !== Node.ELEMENT_NODE) {
146
+ return "";
147
+ }
148
+ const el = node;
149
+ const tag = el.tagName.toLowerCase();
150
+ const isBody = tag === "body";
151
+ const isInsideBody = inBody || isBody;
152
+ if (isInsideBody && skipTags.has(tag)) {
153
+ return "";
154
+ }
155
+ let s = `<${tag}`;
156
+ for (let i = 0; i < el.attributes.length; i++) {
157
+ const attr = el.attributes[i];
158
+ s += ` ${attr.name}="${attr.value.replace(/"/g, "&quot;")}"`;
159
+ }
160
+ const voidElements = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
161
+ if (voidElements.has(tag)) {
162
+ s += ">";
163
+ return s;
164
+ }
165
+ s += ">";
166
+ if (el.shadowRoot) {
167
+ s += `<template shadowrootmode="${el.shadowRoot.mode}">`;
168
+ for (let i = 0; i < el.shadowRoot.childNodes.length; i++) {
169
+ s += serializeNode(el.shadowRoot.childNodes[i], isInsideBody);
170
+ }
171
+ s += "</template>";
172
+ }
173
+ for (let i = 0; i < el.childNodes.length; i++) {
174
+ s += serializeNode(el.childNodes[i], isInsideBody);
175
+ }
176
+ s += `</${tag}>`;
177
+ return s;
178
+ }
179
+ let result = "<!DOCTYPE html>\n<html";
180
+ const htmlNode = document.documentElement;
181
+ for (let i = 0; i < htmlNode.attributes.length; i++) {
182
+ const attr = htmlNode.attributes[i];
183
+ result += ` ${attr.name}="${attr.value.replace(/"/g, "&quot;")}"`;
184
+ }
185
+ result += ">\n";
186
+ if (document.head) result += serializeNode(document.head, false);
187
+ result += "\n";
188
+ if (document.body) result += serializeNode(document.body, true);
189
+ result += "\n</html>";
190
+ return result;
191
+ }, this.config.playwright?.ignoreTags || []);
192
+ console.log(`\u{1F488} [SSR:Playwright] Successfully rendered ${targetUrl}`);
193
+ await this.writeOkHtmlAndEnd({ rr }, this.makeHTML(html));
194
+ } catch (e) {
195
+ console.error(`Playwright SSR Error for ${targetUrl}:`, e);
196
+ return true;
65
197
  } finally {
66
- window.close?.();
67
- domParserInitializer.destroy();
198
+ await context.close();
68
199
  }
69
200
  return false;
70
201
  }
71
202
  return true;
72
203
  }
73
- makeHTML(window) {
74
- let html = window.document.documentElement.outerHTML;
204
+ makeHTML(html) {
75
205
  if (!/^<!DOCTYPE html>/i.test(html)) {
76
206
  html = "<!DOCTYPE html>\n" + html;
77
207
  }