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

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 (43) hide show
  1. package/README.md +87 -38
  2. package/dist/cjs/bundle-entry.js +46 -12
  3. package/dist/cjs/bundle-entry.js.map +2 -2
  4. package/dist/cjs/filters/SSRDomParserFilter.js +4 -3
  5. package/dist/cjs/filters/SSRDomParserFilter.js.map +2 -2
  6. package/dist/cjs/filters/SSRFilter.js +4 -3
  7. package/dist/cjs/filters/SSRFilter.js.map +2 -2
  8. package/dist/cjs/filters/SSRLinkDomFilter.js +4 -3
  9. package/dist/cjs/filters/SSRLinkDomFilter.js.map +2 -2
  10. package/dist/cjs/filters/SSRSimpleWebComponentDomParserFilter.js +50 -2
  11. package/dist/cjs/filters/SSRSimpleWebComponentDomParserFilter.js.map +2 -2
  12. package/dist/cjs/filters/SSRSimpleWebComponentFilter.js.map +1 -1
  13. package/dist/esm/bundle-entry.js +22 -6
  14. package/dist/esm/bundle-entry.js.map +2 -2
  15. package/dist/esm/filters/SSRDomParserFilter.js +5 -4
  16. package/dist/esm/filters/SSRDomParserFilter.js.map +2 -2
  17. package/dist/esm/filters/SSRFilter.js +4 -3
  18. package/dist/esm/filters/SSRFilter.js.map +2 -2
  19. package/dist/esm/filters/SSRLinkDomFilter.js +4 -3
  20. package/dist/esm/filters/SSRLinkDomFilter.js.map +2 -2
  21. package/dist/esm/filters/SSRSimpleWebComponentDomParserFilter.js +50 -2
  22. package/dist/esm/filters/SSRSimpleWebComponentDomParserFilter.js.map +2 -2
  23. package/dist/esm/filters/SSRSimpleWebComponentFilter.js.map +1 -1
  24. package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js +33495 -24465
  25. package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js.map +4 -4
  26. package/dist/types/bundle-entry.d.ts +11 -6
  27. package/dist/types/bundle-entry.d.ts.map +1 -1
  28. package/dist/types/filters/SSRDomParserFilter.d.ts.map +1 -1
  29. package/dist/types/filters/SSRFilter.d.ts.map +1 -1
  30. package/dist/types/filters/SSRLinkDomFilter.d.ts.map +1 -1
  31. package/dist/types/filters/SSRSimpleWebComponentDomParserFilter.d.ts +14 -2
  32. package/dist/types/filters/SSRSimpleWebComponentDomParserFilter.d.ts.map +1 -1
  33. package/dist/types/filters/SSRSimpleWebComponentFilter.d.ts +1 -1
  34. package/dist/types/filters/SSRSimpleWebComponentFilter.d.ts.map +1 -1
  35. package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js +32485 -23456
  36. package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js.map +4 -4
  37. package/package.json +12 -12
  38. package/src/bundle-entry.ts +16 -6
  39. package/src/filters/SSRDomParserFilter.ts +5 -4
  40. package/src/filters/SSRFilter.ts +4 -3
  41. package/src/filters/SSRLinkDomFilter.ts +4 -3
  42. package/src/filters/SSRSimpleWebComponentDomParserFilter.ts +81 -5
  43. package/src/filters/SSRSimpleWebComponentFilter.ts +1 -1
@@ -1,5 +1,6 @@
1
1
  import { HttpHeaders } from "@dooboostore/simple-boot-http-server/codes/HttpHeaders";
2
- import { AsyncBlockingQueue, RandomUtils, MessageOperator, MessageInternal } from "@dooboostore/core";
2
+ import { AsyncBlockingQueue, RandomUtils, firstValueFrom } from "@dooboostore/core";
3
+ import { first } from "@dooboostore/core/message/operators";
3
4
  import { Mimes } from "@dooboostore/simple-boot-http-server/codes/Mimes";
4
5
  import { HttpStatus } from "@dooboostore/simple-boot-http-server/codes/HttpStatus";
5
6
  import { NotFoundError } from "@dooboostore/simple-boot-http-server/errors/NotFoundError";
@@ -82,7 +83,7 @@ class SSRLinkDomFilter {
82
83
  const targetUrl = url.toString();
83
84
  await simpleBootFront.goRouting(targetUrl);
84
85
  await new Promise((r) => setTimeout(r, 0));
85
- const data = await MessageInternal.firstValueFrom(
86
+ const data = await firstValueFrom(
86
87
  // @ts-ignore
87
88
  simpleBootFront.routingObservable.pipe(
88
89
  // @ts-ignore
@@ -90,7 +91,7 @@ class SSRLinkDomFilter {
90
91
  (it) => it.triggerPoint === "end" && typeof it.routerModule.intent.uri === "string" && targetUrl.endsWith(it.routerModule.intent.uri)
91
92
  ),
92
93
  // delay(1000),
93
- MessageOperator.first()
94
+ first()
94
95
  )
95
96
  );
96
97
  const html = this.makeHTML(simpleBootFront);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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": "AACA,SAAS,mBAAmB;AAE5B,SAA0B,oBAAoB,aAAa,iBAAiB,uBAAuB;AAGnG,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAK3B,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAE/B,SAAS,2BAA2B;AAoB7B,MAAM,iBAAmC;AAAA,EAQ9C,YACS,QACA,kBACP;AAFO;AACA;AATT,SAAQ,sBAAyC,CAAC;AAClD,SAAQ,uBAAuB,IAAI,mBAAoC;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;AAAA,EAEA,MAAM,YAAY;AAChB,QAAI,KAAK,YAAY;AACnB,oBAAc,KAAK,UAAU;AAAA,IAC/B;AAEA,SAAK,oBAAoB,QAAQ,WAAS;AAC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ACF;",
4
+ "sourcesContent": ["import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';\nimport { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';\nimport { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';\nimport { ConstructorType, AsyncBlockingQueue, RandomUtils, firstValueFrom } from '@dooboostore/core';\nimport { first } from '@dooboostore/core/message/operators';\nimport { JsdomInitializer } from '../initializers/JsdomInitializer';\nimport { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';\nimport { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';\nimport { HttpStatus } from '@dooboostore/simple-boot-http-server/codes/HttpStatus';\nimport { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';\nimport { SimFrontOption } from '@dooboostore/simple-boot-front/option/SimFrontOption';\nimport { SimpleBootFront } from '@dooboostore/simple-boot-front/SimpleBootFront';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render';\nimport { parseHTML } from 'linkedom';\nimport { LinkedomInitializer } from '../initializers/LinkedomInitializer';\n\nexport type LinkDomFactoryAndParams = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n factorySimFrontOption: (window: any) => SimFrontOption;\n factory: SimpleBootHttpSSRFactory;\n poolOption: {\n max: number;\n min: number;\n clearIntervalTime?: number;\n };\n using: ConstructorType<any>[];\n domExcludes?: ConstructorType<any>[];\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n simpleBootFront?: {\n notFoundError?: boolean;\n };\n};\n\nexport class SSRLinkDomFilter implements Filter {\n private simpleBootFrontPool: SimpleBootFront[] = [];\n private simpleBootFrontQueue = new AsyncBlockingQueue<SimpleBootFront>();\n // private indexHTML: string;\n private welcomUrl = 'http://localhost';\n private poolGeneration = 0;\n private intervalId?: NodeJS.Timeout;\n\n constructor(\n public config: LinkDomFactoryAndParams,\n public otherInstanceSim?: Map<ConstructorType<any>, any>\n ) {\n config.frontDistIndexFileName = config.frontDistIndexFileName || 'index.html';\n // this.indexHTML = JsdomInitializer.loadFile(this.config.frontDistPath, config.frontDistIndexFileName);\n }\n\n async onInit(app: SimpleBootHttpServer) {\n for (let i = 0; i < this.config.poolOption.min; i++) {\n await this.pushQueue();\n }\n\n if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {\n this.intervalId = setInterval(() => {\n this.poolGeneration++;\n }, this.config.poolOption.clearIntervalTime);\n }\n }\n\n async onDestroy() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n // this.simpleBootFrontQueue.clear();\n this.simpleBootFrontPool.forEach(front => {\n (front as any).jsdom?.window.close();\n });\n this.simpleBootFrontPool = [];\n }\n\n async makePage() {\n return new LinkedomInitializer(\n this.config.frontDistPath,\n this.config.frontDistIndexFileName || 'index.html',\n { url: this.welcomUrl }\n ).run();\n // const jsdom = await new JsdomInitializer(\n // this.config.frontDistPath,\n // this.config.frontDistIndexFileName || 'index.html',\n // { url: this.welcomUrl }\n // ).run();\n // return jsdom;\n }\n\n async makeFront(window: Window) {\n const name = RandomUtils.uuid();\n (window as any).ssrUse = false;\n const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));\n const simpleBootFront = await this.config.factory.create(option, this.config.using, this.config.domExcludes);\n simpleBootFront.run(this.otherInstanceSim);\n (simpleBootFront as any).generation = this.poolGeneration;\n return simpleBootFront;\n }\n\n enqueueFrontApp(simpleBootFront: SimpleBootFront) {\n // this.simpleBootFrontPool.set(simpleBootFront.option.name!, simpleBootFront);\n this.simpleBootFrontPool.push(simpleBootFront);\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n async pushQueue() {\n if (this.simpleBootFrontPool.length < this.config.poolOption.max) {\n this.enqueueFrontApp(await this.makeFront(await this.makePage()));\n }\n }\n\n async proceedBefore({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return false;\n }\n if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {\n if (this.simpleBootFrontQueue.isEmpty()) {\n await this.pushQueue();\n }\n const simpleBootFront = await this.simpleBootFrontQueue.dequeue();\n try {\n (simpleBootFront.option.window as any).ssrUse = true;\n delete (simpleBootFront.option.window as any).server_side_data;\n const url = rr.reqUrlObj({ host: 'localhost' });\n if (this.config.simpleBootFront?.notFoundError) {\n // intent router check first\n const intent = await simpleBootFront.routingRouterModule(url.pathname);\n // route\uB97C \uBABB\uCC3E\uC740\uC0C1\uD0DC\uC5D0\uC11C router path\uAE4C\uC9C0 \uC548\uB9DE\uC73C\uBA74 404 \uCC98\uB9AC\uD55C\uB2E4. route\uB791 router\uB791 \uB2E4\uB974\uB2C8\uAE50 \uD5DB\uAC08\uB9AC\uC9C0\uB9D0\uB3C4\uB85D\n if (intent.module === undefined && !intent.getRouterPathData(rr.reqUrlPathName)) {\n throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });\n }\n }\n\n // runRouting!!\n const targetUrl = url.toString();\n await simpleBootFront.goRouting(targetUrl);\n await new Promise(r => setTimeout(r, 0)); // <--\uC911\uC694: \uC774\uAC70 \uB123\uC5B4\uC57C\uC9C0 \uB450\uBC88\uBD88\uB7EC\uC9C0\uB294\uAC8C \uC5C6\uC5B4\uC9C0\uB294\uB4EF? \uBB50\uC9C0 event loop \uBCC0\uACBD\uB41C\uAC74\uAC00?\n\n\n // simpleBootFront.routingSubjectObservable.subscribe(it=>{\n // console.log('zzzzzzzzzzzzzzzzzzz', it);\n // if (it.triggerPoint==='end') {\n // console.log('zzz@@', it.routerModule.intent);\n // }\n // })\n\n const data = await firstValueFrom(\n // @ts-ignore\n simpleBootFront.routingObservable.pipe(\n // @ts-ignore\n MessageOperator.filter(\n (it) =>\n it.triggerPoint === 'end' &&\n typeof it.routerModule.intent.uri === 'string' &&\n targetUrl.endsWith(it.routerModule.intent.uri)\n ),\n // delay(1000),\n first()\n )\n );\n // console.log('???????done');\n const html = this.makeHTML(simpleBootFront);\n await this.writeOkHtmlAndEnd({ rr }, html);\n } finally {\n (simpleBootFront.option.window as any).ssrUse = false;\n delete (simpleBootFront.option.window as any).server_side_data;\n if ((simpleBootFront as any).generation < this.poolGeneration) {\n // Stale instance, destroy it\n const jsdom = (simpleBootFront as any).jsdom as JSDOM.JSDOM | undefined;\n jsdom?.window.close();\n const index = this.simpleBootFrontPool.indexOf(simpleBootFront);\n if (index > -1) {\n this.simpleBootFrontPool.splice(index, 1);\n }\n this.pushQueue();\n } else {\n // Current instance, return to queue\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n }\n return false;\n } else {\n return true;\n }\n }\n\n makeHTML(simpleBootFront: SimpleBootFront) {\n (simpleBootFront.option.window as any).document.querySelectorAll('*').forEach((el:HTMLElement )=> {\n Array.from(el.attributes).forEach(attr => {\n if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {\n el.removeAttribute(attr.name);\n }\n });\n });\n let html = simpleBootFront.option.window.document.documentElement.outerHTML;\n html = '<!DOCTYPE html>' + html;\n html = html.replace(/\\$\\{[\\s\\S]*?\\}\\$/g, '');\n const serverSideData = (simpleBootFront.option.window as any).server_side_data;\n if (serverSideData) {\n const data = Object.entries(serverSideData)\n .map(([k, v]) => {\n if (typeof v === 'string') {\n return `window.server_side_data.${k} = ${v}`;\n } else {\n return `window.server_side_data.${k} = ${JSON.stringify(v)}`;\n }\n })\n .join(';');\n if (data) {\n html = html.replace('</head>', `<script> window.server_side_data={}; ${data}; </script></head>`);\n }\n }\n return html;\n }\n async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }: { rr: RequestResponse; status?: HttpStatus }, html: string) {\n rr.resStatusCode(status);\n rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);\n await rr.resEnd(html);\n }\n\n async proceedAfter({ rr, app }: { r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ACxF,aAAG,gBAAgB,KAAK,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
6
  "names": []
7
7
  }
@@ -1,7 +1,9 @@
1
1
  import { HttpHeaders } from "@dooboostore/simple-boot-http-server/codes/HttpHeaders";
2
2
  import { Mimes } from "@dooboostore/simple-boot-http-server/codes/Mimes";
3
3
  import { HttpStatus } from "@dooboostore/simple-boot-http-server/codes/HttpStatus";
4
+ import { injectRequestResponse } from "@dooboostore/simple-boot-http-server/proxy/RequestResponseInjectProxy";
4
5
  import { DomParserInitializer } from "../initializers/DomParserInitializer.js";
6
+ import { findAllPropertyMetadata } from "@dooboostore/simple-web-component";
5
7
  class SSRSimpleWebComponentDomParserFilter {
6
8
  constructor(config) {
7
9
  this.config = config;
@@ -9,6 +11,7 @@ class SSRSimpleWebComponentDomParserFilter {
9
11
  this.welcomUrl = config.welcomUrl || this.welcomUrl;
10
12
  }
11
13
  async onInit(app) {
14
+ this.app = app;
12
15
  }
13
16
  async onDestroy() {
14
17
  }
@@ -19,12 +22,57 @@ class SSRSimpleWebComponentDomParserFilter {
19
22
  if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {
20
23
  const url = rr.reqUrlObj({ host: "localhost" });
21
24
  const targetUrl = url.toString() ?? this.welcomUrl;
25
+ console.log("SSRSimpleWebComponentDomParserFilter start");
22
26
  const domParserInitializer = new DomParserInitializer(this.config.frontDistPath, this.config.frontDistIndexFileName || "index.html", { url: targetUrl });
23
27
  const window = await domParserInitializer.run();
24
- console.log("vvvv22aa");
25
28
  try {
29
+ let app;
26
30
  if (this.config.registerComponents) {
27
- await this.config.registerComponents(window);
31
+ const sim = /* @__PURE__ */ new Map();
32
+ for (const service of (this.config.intentServices ?? []).filter(Boolean)) {
33
+ if (!service.symbol) continue;
34
+ for (const sym of Array.isArray(service.symbol) ? service.symbol : [service.symbol]) {
35
+ const raw = this.app?.sim(sym);
36
+ if (raw) sim.set(sym, injectRequestResponse(raw, rr));
37
+ }
38
+ }
39
+ app = await this.config.registerComponents(window, rr, sim);
40
+ }
41
+ if (app) {
42
+ const items = [];
43
+ const targets = [app, ...(app.connectedElements?.() ?? []).filter((el) => el !== app)];
44
+ for (const el of targets) {
45
+ const swcId = el._swcId;
46
+ if (!swcId) continue;
47
+ const sel = `[swc-use-ssr="${swcId}"]`;
48
+ for (const m of findAllPropertyMetadata(el)) {
49
+ let value;
50
+ try {
51
+ value = el[m.propertyKey];
52
+ } catch {
53
+ continue;
54
+ }
55
+ if (value === void 0 || typeof value === "function") continue;
56
+ try {
57
+ JSON.stringify(value);
58
+ } catch {
59
+ continue;
60
+ }
61
+ items.push({ sel, prop: String(m.propertyKey), value });
62
+ }
63
+ }
64
+ if (items.length > 0) {
65
+ const script = window.document.createElement("script");
66
+ const hydrationJson = JSON.stringify(items).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
67
+ script.textContent = ` window.__swc_hydration=${hydrationJson};for(const h of window.__swc_hydration){
68
+ const el=document.querySelector(h.sel);
69
+ if(el){
70
+ el[h.prop]=h.value;
71
+ }
72
+ }`;
73
+ window.document.body.appendChild(script);
74
+ console.log(`[ssr-hydration] ${items.length} props embedded`);
75
+ }
28
76
  }
29
77
  const html = this.makeHTML(window);
30
78
  await this.writeOkHtmlAndEnd({ rr }, html);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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": "AACA,SAAQ,mBAAkB;AAE1B,SAAQ,aAAY;AACpB,SAAQ,kBAAiB;AAEzB,SAAQ,4BAA2B;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,MAAM,YAAY;AAAA,EAAC;AAAA,EAEnB,MAAM,cAAc,EAAE,GAAG,GAAkF;AACzG,QAAI,KAAK,OAAO,mBAAmB,EAAE,GAAG;AACtC,aAAO;AAAA,IACT;AAEA,QAAI,GAAG,mBAAmB,MAAM,QAAQ,KAAK,GAAG,mBAAmB,MAAM,GAAG,GAAG;AAC7E,YAAM,MAAM,GAAG,UAAU,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAM,YAAY,IAAI,SAAS,KAAK,KAAK;AAGzC,YAAM,uBAAuB,IAAI,qBAAqB,KAAK,OAAO,eAAe,KAAK,OAAO,0BAA0B,cAAc,EAAE,KAAK,UAAU,CAAC;AACvJ,YAAM,SAAS,MAAM,qBAAqB,IAAI;AAE9C,cAAQ,IAAI,UAAU;AAetB,UAAI;AAGF,YAAI,KAAK,OAAO,oBAAoB;AAClC,gBAAM,KAAK,OAAO,mBAAmB,MAAM;AAAA,QAC7C;AAQA,cAAM,OAAO,KAAK,SAAS,MAAM;AAEjC,cAAM,KAAK,kBAAkB,EAAE,GAAG,GAAG,IAAI;AAAA,MAC3C,UAAE;AAEA,eAAO,MAAM;AACb,6BAAqB,QAAQ;AAAA,MAC/B;AACA,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,QAAa;AACpB,QAAI,OAAO,OAAO,SAAS,gBAAgB;AAC3C,QAAI,CAAC,oBAAoB,KAAK,IAAI,GAAG;AACnC,aAAO,sBAAsB;AAAA,IAC/B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,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,eAAe;AACnB,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 {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 {injectRequestResponse} from '@dooboostore/simple-boot-http-server/proxy/RequestResponseInjectProxy';\nimport {SimConfig} from '@dooboostore/simple-boot';\nimport {DomParserInitializer} from '../initializers/DomParserInitializer';\nimport type { SwcAppInterface } from '@dooboostore/simple-web-component';\nimport { findAllPropertyMetadata } from '@dooboostore/simple-web-component';\n\nexport type SWCSSRDomParserConfig = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n welcomUrl?: string;\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n /**\n * SSR \uC5D0 \uB178\uCD9C\uD560 \uBC31\uC5D4\uB4DC \uC11C\uBE44\uC2A4 \uBAA9\uB85D(\uAC01 \uD56D\uBAA9\uC740 symbol \uC744 \uAC00\uC9C4\uB2E4, \uC608: pairServices).\n * \uD504\uB808\uC784\uC6CC\uD06C\uAC00 \uC694\uCCAD\uB9C8\uB2E4 \uAC01 \uC11C\uBE44\uC2A4\uB97C \uAEBC\uB0B4 \uC774 \uC694\uCCAD\uC758 rr \uC744 \uC8FC\uC785\uD55C \uB4A4 Map \uC73C\uB85C \uBB36\uC5B4\n * registerComponents \uC758 3\uBC88\uC9F8 \uC778\uC790(sim)\uB85C \uB118\uAE34\uB2E4. \u2192 \uC571\uC740 \uADF8 Map \uC744 bootfactory \uC5D0 \uADF8\uB300\uB85C \uC804\uB2EC\uB9CC \uD558\uBA74 \uB418\uACE0\n * \uC9C1\uC811 Proxy \uB85C \uAC10\uC2F8\uAC70\uB098 rr \uC744 \uB123\uC744 \uD544\uC694\uAC00 \uC5C6\uB2E4(\uCFE0\uD0A4 \uB4F1 \uC694\uCCAD \uCEE8\uD14D\uC2A4\uD2B8 \uC790\uB3D9 \uC804\uB2EC).\n */\n intentServices?: SimConfig[];\n /**\n * \uC694\uCCAD\uB9C8\uB2E4 \uCEF4\uD3EC\uB10C\uD2B8\uB97C \uB4F1\uB85D\uD55C\uB2E4. \uC571 bootfactory\uB97C \uADF8\uB300\uB85C \uB118\uAE30\uBA74 \uB41C\uB2E4.\n * @param sim intentServices \uB97C rr \uC8FC\uC785\uD574 \uBB36\uC740 Map<symbol, service>. bootfactory \uC5D0 \uADF8\uB300\uB85C \uB118\uAE30\uBA74 \uB41C\uB2E4.\n * @returns \uCD08\uAE30\uD654\uB41C SwcApp (\uD558\uC774\uB4DC\uB808\uC774\uC158 \uB370\uC774\uD130 \uBC15\uC81C \uB4F1\uC5D0 \uC0AC\uC6A9)\n */\n registerComponents?: (window: any, rr: RequestResponse, sim: Map<symbol, any>) => Promise<SwcAppInterface | void> | SwcAppInterface | 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 private app?: SimpleBootHttpServer;\n\n constructor(public config: SWCSSRDomParserConfig) {\n this.welcomUrl = config.welcomUrl || this.welcomUrl;\n }\n\n async onInit(app: SimpleBootHttpServer) {\n this.app = app;\n }\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 console.log('SSRSimpleWebComponentDomParserFilter start');\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 // 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 let app: SwcAppInterface | void;\n if (this.config.registerComponents) {\n // intentServices \uB97C rr \uC8FC\uC785\uD574 Map \uC73C\uB85C \uBB36\uC5B4 \uB118\uAE34\uB2E4 (\uC571\uC740 bootfactory \uC5D0 \uADF8\uB300\uB85C \uC804\uB2EC\uB9CC).\n const sim = new Map<symbol, any>();\n for (const service of (this.config.intentServices ?? []).filter(Boolean)) {\n if (!service.symbol) continue;\n for (const sym of (Array.isArray(service.symbol) ? service.symbol : [service.symbol])) {\n const raw = this.app?.sim<any>(sym as any);\n if (raw) sim.set(sym, injectRequestResponse(raw, rr));\n }\n }\n app = await this.config.registerComponents(window, rr, sim);\n }\n\n // [\uD558\uC774\uB4DC\uB808\uC774\uC158] swcApp \uBCF8\uCCB4 + \uC5F0\uACB0 \uC5D8\uB9AC\uBA3C\uD2B8\uC758 @property \uAC12\uC744 script\uB85C \uBC15\uC81C.\n // \uD074\uB77C\uC5D0\uC11C \uBC88\uB4E4\uBCF4\uB2E4 \uBA3C\uC800 \uC2E4\uD589 \u2192 querySelector\uB85C \uCC3E\uC544 .prop = \uAC12 \uC138\uD305 (\uB124\uC774\uD2F0\uBE0C\n // \uC5C5\uADF8\uB808\uC774\uB4DC\uB294 own property \uC720\uC9C0\uB77C upgrade \uD6C4\uC5D0\uB3C4 \uAC12 \uC0B4\uC544\uC788\uC74C).\n if (app) {\n const items: Array<{ sel: string; prop: string; value: unknown }> = [];\n const targets: any[] = [app, ...(app.connectedElements?.() ?? []).filter((el: any) => el !== app)];\n for (const el of targets) {\n const swcId = (el as any)._swcId;\n if (!swcId) continue;\n const sel = `[swc-use-ssr=\"${swcId}\"]`;\n for (const m of findAllPropertyMetadata(el)) {\n let value: unknown;\n try {\n value = el[m.propertyKey];\n } catch {\n continue;\n }\n if (value === undefined || typeof value === 'function') continue;\n try {\n JSON.stringify(value);\n } catch {\n continue;\n }\n items.push({ sel, prop: String(m.propertyKey), value });\n }\n }\n if (items.length > 0) {\n // \uC5C5\uADF8\uB808\uC774\uB4DC \uB54C \uB178\uB4DC\uAC00 \uAC08\uC544\uC5CE\uC5B4\uC9C0\uBA74 JS \uD504\uB85C\uD37C\uD2F0\uB294 \uB0A0\uC544\uAC10. attribute\uB294 \uBCF5\uC0AC\uB418\uB2C8\n // data-hyd-* \uB85C \uBC15\uACE0, \uAC19\uC740 \uB178\uB4DC\uBA74 \uD504\uB85C\uD37C\uD2F0\uB3C4 \uBC14\uB85C \uC138\uD305.\n const script = window.document.createElement('script');\n // <script> \uB0B4\uC6A9\uC740 \uC774\uC2A4\uCF00\uC774\uD504 \uC5C6\uC774 \uC9C1\uB82C\uD654\uB41C\uB2E4 \u2192 \uAC12\uC5D0 '</script>'\uAC00 \uC788\uC73C\uBA74 HTML \uD30C\uC11C\uAC00 \uAC70\uAE30\uC11C \uD0DC\uADF8\uB97C \uB2EB\uC544 XSS.\n // JSON.stringify\uB294 '<'\uB97C \uC774\uC2A4\uCF00\uC774\uD504\uD558\uC9C0 \uC54A\uC73C\uBBC0\uB85C '\\u003c'\uB85C \uBC14\uAFBC\uB2E4 (JS\uC5D0\uC120 \uAC19\uC740 \uBB38\uC790\uC5F4).\n // U+2028/2029\uB294 \uAD6C\uD615 JS \uC5D4\uC9C4\uC5D0\uC11C \uBB38\uC790\uC5F4 \uB9AC\uD130\uB7F4 \uC548\uC758 \uC904\uBC14\uAFC8\uC73C\uB85C \uD574\uC11D\uB3FC \uBB38\uBC95 \uC624\uB958\uAC00 \uB098\uBBC0\uB85C \uD568\uAED8 \uC774\uC2A4\uCF00\uC774\uD504.\n const hydrationJson = JSON.stringify(items)\n .replace(/</g, '\\\\u003c')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n script.textContent =\n ` window.__swc_hydration=${hydrationJson};` +\n `for(const h of window.__swc_hydration){\n const el=document.querySelector(h.sel);\n if(el){\n el[h.prop]=h.value;\n }\n }`;\n window.document.body.appendChild(script);\n console.log(`[ssr-hydration] ${items.length} props embedded`);\n }\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": "AACA,SAAQ,mBAAkB;AAE1B,SAAQ,aAAY;AACpB,SAAQ,kBAAiB;AAEzB,SAAQ,6BAA4B;AAEpC,SAAQ,4BAA2B;AAEnC,SAAS,+BAA+B;AA0BjC,MAAM,qCAAuD;AAAA,EAIlE,YAAmB,QAA+B;AAA/B;AAHnB,SAAQ,YAAY;AAIlB,SAAK,YAAY,OAAO,aAAa,KAAK;AAAA,EAC5C;AAAA,EAEA,MAAM,OAAO,KAA2B;AACtC,SAAK,MAAM;AAAA,EACb;AAAA,EAEA,MAAM,YAAY;AAAA,EAAC;AAAA,EAEnB,MAAM,cAAc,EAAE,GAAG,GAAkF;AACzG,QAAI,KAAK,OAAO,mBAAmB,EAAE,GAAG;AACtC,aAAO;AAAA,IACT;AAEA,QAAI,GAAG,mBAAmB,MAAM,QAAQ,KAAK,GAAG,mBAAmB,MAAM,GAAG,GAAG;AAC7E,YAAM,MAAM,GAAG,UAAU,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAM,YAAY,IAAI,SAAS,KAAK,KAAK;AACzC,cAAQ,IAAI,4CAA4C;AAGxD,YAAM,uBAAuB,IAAI,qBAA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G;AAGpB,kBAAM,SAAS,OAAO,SAAS,cAAc,QAAQ;AAIrD,kBAAM,gBAAgB,KAAK,UAAU,KAAK,EACvC,QAAQ,MAAM,SAAS,EACvB,QAAQ,WAAW,SAAS,EAC5B,QAAQ,WAAW,SAAS;AAC/B,mBAAO,cACL,2BAA2B,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAO1C,mBAAO,SAAS,KAAK,YAAY,MAAM;AACvC,oBAAQ,IAAI,mBAAmB,MAAM,MAAM,iBAAiB;AAAA,UAC9D;AAAA,QACF;AAQA,cAAM,OAAO,KAAK,SAAS,MAAM;AAEjC,cAAM,KAAK,kBAAkB,EAAE,GAAG,GAAG,IAAI;AAAA,MAC3C,UAAE;AAEA,eAAO,MAAM;AACb,6BAAqB,QAAQ;AAAA,MAC/B;AACA,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,QAAa;AACpB,QAAI,OAAO,OAAO,SAAS,gBAAgB;AAC3C,QAAI,CAAC,oBAAoB,KAAK,IAAI,GAAG;AACnC,aAAO,sBAAsB;AAAA,IAC/B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,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,eAAe;AACnB,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/filters/SSRSimpleWebComponentFilter.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 path from 'path';\nimport fs from 'fs';\nimport {HttpMethod} from \"@dooboostore/simple-boot-http-server\";\n\nexport type SWCSSRConfig = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n welcomUrl?: string;\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n /**\n * (Deprecated for Playwright)\n * Function to register components for each request.\n * Playwright evaluates real JS files loaded from your index.html,\n * so component registration happens automatically in the browser context.\n */\n registerComponents?: (window: any) => Promise<void> | void;\n playwright?: {\n waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';\n waitForSelector?: string;\n waitForTimeout?: number;\n timeout?: number;\n ignoreTags?: string[];\n };\n};\n\n/**\n * SSR Filter specifically for Simple Web Component (SWC).\n * It utilizes Playwright to render the page robustly and perfectly matching browser specs.\n *\n * ### Playwright Setup & Requirements\n *\n * To use this filter, Playwright must be installed in your server environment:\n * 1. Install playwright package: `npm install playwright` or `pnpm add playwright`\n * 2. Install browsers: `npx playwright install chromium`\n *\n * If running inside a Docker container (e.g., Alpine Linux), you must use an image that supports Playwright\n * or manually install OS dependencies. Playwright provides official Docker images: `mcr.microsoft.com/playwright:v1.x.x-focal`.\n */\nexport class SSRSimpleWebComponentFilter implements Filter {\n private welcomUrl = 'http://localhost';\n private browser?: any;\n\n constructor(public config: SWCSSRConfig) {\n this.welcomUrl = config.welcomUrl || this.welcomUrl;\n }\n\n async onInit(app: SimpleBootHttpServer) {\n // 1. Initialize Playwright browser when the server starts\n const { chromium } = await import('playwright');\n this.browser = await chromium.launch({\n headless: true,\n args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-web-security'] // Allow CORS for local dev\n });\n console.log('\uD83D\uDE80 Playwright Browser initialized for SSR Filter');\n }\n\n async onDestroy() {\n if (this.browser) {\n await this.browser.close();\n console.log('\uD83D\uDED1 Playwright Browser closed');\n }\n }\n\n async proceedBefore({ rr, app, carrier }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return true; // Bypass SSR and continue server chain\n }\n\n console.log('playwright2222222', rr.reqHeader('x-ssr-browser'));\n\n // 2. Prevent Infinite Loop:\n // If the request comes from Playwright itself, bypass SSR and serve the original static SPA file.\n if (rr.reqHeader('x-ssr-browser') === 'playwright') {\n return true;\n }\n\n if (rr.reqIsMethod(HttpMethod.GET) && rr.reqHasContentTypeHeader(Mimes.TextHtml)) {\n // Build target URL for Playwright to visit\n // Use the server's actual listening address and port if available\n const protocol = app.option.protocol || 'http';\n const host = app.option.hostname || '127.0.0.1';\n const port = app.option.port || 80;\n\n const url = rr.reqUrlObj({ host: `${host}:${port}` });\n url.protocol = protocol;\n\n const targetUrl = url.toString() ?? this.welcomUrl;\n\n if (!this.browser) {\n console.error('Playwright browser is not initialized. Bypassing SSR.');\n return true;\n }\n\n // Create a fresh context for isolation\n // IMPORTANT: We do NOT use `extraHTTPHeaders` globally because it attaches the header to EVERY request\n // Playwright makes (including CORS requests to FontAwesome or API requests).\n // Instead, we will set the header ONLY for the initial navigation request to our server.\n const context = await this.browser.newContext();\n const page = await context.newPage();\n\n try {\n // Intercept ONLY requests going to our local server and append the bypass header\n await page.route('**/*', route => {\n const request = route.request();\n\n // Only append the x-ssr-browser header for requests to the local server that are NOT API requests\n const isLocal = request.url().startsWith(targetUrl) || request.url().includes('localhost') || request.url().includes('127.0.0.1');\n const isApi = request.url().includes('/api/');\n\n if (isLocal && !isApi) {\n const headers = {\n ...request.headers(),\n 'x-ssr-browser': 'playwright'\n };\n route.continue({ headers }).catch(() => {});\n } else {\n // For external requests (like font-awesome CORS) or API calls, do not add the custom header\n route.continue().catch(() => {});\n }\n });\n\n // 3. Navigate to the page and wait for the framework to finish rendering\n // but normally Playwright just navigates to the targetUrl and loads the real SPA resources.\n\n // \uD83D\uDCA1 Playwright \u2194 Framework \uD1B5\uC2E0 \uC124\uC815\n // \uD504\uB860\uD2B8\uC5D4\uB4DC\uC758 `bootfactory.ts` \uC548\uC758 `onRouteChanged` \uB4F1\uC5D0\uC11C\n // `if (window.onPlaywrightReady) window.onPlaywrightReady()` \uB77C\uACE0 \uD638\uCD9C\uD574\uC8FC\uBA74,\n // \uC544\uB798\uC758 Promise\uAC00 \uC989\uC2DC resolve \uB418\uB3C4\uB85D \uC5F0\uACB0\uD569\uB2C8\uB2E4.\n let resolvePlaywrightReady: () => void;\n const playwrightReadyPromise = new Promise<void>(resolve => {\n resolvePlaywrightReady = resolve;\n });\n\n await page.exposeFunction('onPlaywrightReady', () => {\n console.log('\u26A1\uFE0F [SSR:Playwright] Received \"onPlaywrightReady\" signal from framework!');\n resolvePlaywrightReady();\n });\n\n // 3. Navigate to the page and wait for the framework to finish rendering\n // Since the server will return the `index.html` (due to the bypass header), Playwright will download\n // your main.js / bundle.js, evaluate it, and the Custom Elements will register themselves naturally!\n await page.goto(targetUrl, {\n waitUntil: this.config.playwright?.waitUntil ?? 'networkidle',\n timeout: this.config.playwright?.timeout ?? 15000\n });\n\n // \uD83D\uDCA1 Framework Load Wait (Crucial for SWC)\n // Wait for EITHER the framework to call `window.onPlaywrightReady()` OR a specific innerHTML condition\n await Promise.race([\n playwrightReadyPromise, // \uC9C1\uC811 exposeFunction\uC5D0\uC11C \uD2B8\uB9AC\uAC70\uB41C Promise\n\n page.waitForFunction(\n () => {\n // Fallback 1: If explicit signal variable is set\n return (window as any)._playwrightReadySignalFired === true;\n },\n { timeout: this.config.playwright?.timeout ?? 15000 }\n ),\n\n page.waitForFunction(\n () => {\n // Fallback 2: If no signal, just wait until body has content\n return document.body.innerHTML.trim().length > 100;\n },\n { timeout: this.config.playwright?.timeout ?? 15000 }\n )\n ]).catch(() => console.log('Wait for app mount timeout... proceeding anyway'));\n\n // \uAC15\uC81C\uB85C \uCEF4\uD3EC\uB10C\uD2B8 \uB80C\uB354\uB9C1 \uBC0F \uD3F0\uD2B8\uC5B4\uC378 \uB4F1 \uB9AC\uC18C\uC2A4 \uB85C\uB529 \uB300\uAE30 \uC2DC\uAC04 \uCD94\uAC00 (\uC548\uC804 \uC7A5\uCE58)\n // onPlaywrightReady \uC2E0\uD638\uAC00 \uB5A8\uC5B4\uC838\uB3C4, \uBE44\uB3D9\uAE30 \uB80C\uB354\uB9C1(SwcLoop \uB4F1)\uC774 DOM\uC5D0 \uC644\uC804\uD788 \uBC18\uC601\uB418\uB294 \uB370\n // \uC57D\uAC04\uC758 Microtask \uC9C0\uC5F0\uC774 \uC788\uC744 \uC218 \uC788\uC73C\uBBC0\uB85C \uC544\uC8FC \uC9E7\uAC8C\uB9CC \uAE30\uB2E4\uB824 \uC90D\uB2C8\uB2E4.\n // await new Promise(resolve => setTimeout(resolve, 300));\n\n // Optional: Wait for a specific component to be visible\n if (this.config.playwright?.waitForSelector) {\n await page.waitForSelector(this.config.playwright.waitForSelector, {\n timeout: this.config.playwright?.timeout ?? 15000\n });\n }\n\n // Optional: Hardcoded wait time if explicitly set (fallback)\n if (this.config.playwright?.waitForTimeout) {\n await page.waitForTimeout(this.config.playwright.waitForTimeout);\n }\n\n // 4. Set SSR Attribute before extracting HTML\n await page.evaluate(() => {\n document.body.setAttribute('ssr-use', 'true');\n });\n\n // 5. Generate Final HTML\n const html = await page.evaluate(ignoreTags => {\n const skipTags = new Set(ignoreTags || []);\n\n function serializeNode(node: Node, inBody: boolean = false): string {\n if (node.nodeType === Node.TEXT_NODE) {\n const text = node.textContent || '';\n return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n }\n if (node.nodeType === Node.COMMENT_NODE) {\n return `<!--${node.textContent}-->`;\n }\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return '';\n }\n\n const el = node as Element;\n const tag = el.tagName.toLowerCase();\n const isBody = tag === 'body';\n const isInsideBody = inBody || isBody;\n\n // \uD83D\uDEAB Skip ignored tags (like <style>) ONLY if we are inside the <body>.\n // This ensures <style> tags in the <head> (global styles) are preserved!\n if (isInsideBody && skipTags.has(tag)) {\n return '';\n }\n\n let s = `<${tag}`;\n\n // 1. Serialize Attributes\n for (let i = 0; i < el.attributes.length; i++) {\n const attr = el.attributes[i];\n s += ` ${attr.name}=\"${attr.value.replace(/\"/g, '&quot;')}\"`;\n }\n\n // Handle void elements (self-closing)\n const voidElements = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);\n if (voidElements.has(tag)) {\n s += '>';\n return s;\n }\n s += '>';\n\n // 2. Serialize Shadow DOM (Declarative Shadow DOM)\n // MUST KEEP for SSR: Without this, the user receives an empty shell until JS loads and re-renders everything.\n // This allows the browser to paint the full UI (including styles inside the component) immediately.\n if (el.shadowRoot) {\n s += `<template shadowrootmode=\"${el.shadowRoot.mode}\">`;\n for (let i = 0; i < el.shadowRoot.childNodes.length; i++) {\n s += serializeNode(el.shadowRoot.childNodes[i], isInsideBody);\n }\n s += '</template>';\n }\n\n // 3. Serialize Light DOM Children\n for (let i = 0; i < el.childNodes.length; i++) {\n s += serializeNode(el.childNodes[i], isInsideBody);\n }\n\n s += `</${tag}>`;\n return s;\n }\n\n let result = '<!DOCTYPE html>\\n<html';\n const htmlNode = document.documentElement;\n for (let i = 0; i < htmlNode.attributes.length; i++) {\n const attr = htmlNode.attributes[i];\n result += ` ${attr.name}=\"${attr.value.replace(/\"/g, '&quot;')}\"`;\n }\n result += '>\\n';\n\n if (document.head) result += serializeNode(document.head, false);\n result += '\\n';\n if (document.body) result += serializeNode(document.body, true);\n\n result += '\\n</html>';\n return result;\n }, this.config.playwright?.ignoreTags || []);\n console.log(`\uD83D\uDC88 [SSR:Playwright] Successfully rendered ${targetUrl}`);\n\n await this.writeOkHtmlAndEnd({ rr }, this.makeHTML(html));\n } catch (e) {\n console.error(`Playwright SSR Error for ${targetUrl}:`, e);\n // If Playwright fails (e.g., timeout), we bypass SSR so the client at least gets the CSR app\n return true;\n } finally {\n await context.close();\n }\n return false; // Tell SimpleBootHttpServer to stop routing because we've handled the response\n }\n return true;\n }\n\n makeHTML(html: string) {\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"],
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 path from 'path';\nimport fs from 'fs';\nimport {HttpMethod} from \"@dooboostore/simple-boot-http-server\";\n\nexport type SWCSSRConfig = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n welcomUrl?: string;\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n /**\n * (Deprecated for Playwright)\n * Function to register components for each request.\n * Playwright evaluates real JS files loaded from your index.html,\n * so component registration happens automatically in the browser context.\n */\n registerComponents?: (window: any, rr?: RequestResponse) => Promise<void> | void;\n playwright?: {\n waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';\n waitForSelector?: string;\n waitForTimeout?: number;\n timeout?: number;\n ignoreTags?: string[];\n };\n};\n\n/**\n * SSR Filter specifically for Simple Web Component (SWC).\n * It utilizes Playwright to render the page robustly and perfectly matching browser specs.\n *\n * ### Playwright Setup & Requirements\n *\n * To use this filter, Playwright must be installed in your server environment:\n * 1. Install playwright package: `npm install playwright` or `pnpm add playwright`\n * 2. Install browsers: `npx playwright install chromium`\n *\n * If running inside a Docker container (e.g., Alpine Linux), you must use an image that supports Playwright\n * or manually install OS dependencies. Playwright provides official Docker images: `mcr.microsoft.com/playwright:v1.x.x-focal`.\n */\nexport class SSRSimpleWebComponentFilter implements Filter {\n private welcomUrl = 'http://localhost';\n private browser?: any;\n\n constructor(public config: SWCSSRConfig) {\n this.welcomUrl = config.welcomUrl || this.welcomUrl;\n }\n\n async onInit(app: SimpleBootHttpServer) {\n // 1. Initialize Playwright browser when the server starts\n const { chromium } = await import('playwright');\n this.browser = await chromium.launch({\n headless: true,\n args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-web-security'] // Allow CORS for local dev\n });\n console.log('\uD83D\uDE80 Playwright Browser initialized for SSR Filter');\n }\n\n async onDestroy() {\n if (this.browser) {\n await this.browser.close();\n console.log('\uD83D\uDED1 Playwright Browser closed');\n }\n }\n\n async proceedBefore({ rr, app, carrier }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return true; // Bypass SSR and continue server chain\n }\n\n console.log('playwright2222222', rr.reqHeader('x-ssr-browser'));\n\n // 2. Prevent Infinite Loop:\n // If the request comes from Playwright itself, bypass SSR and serve the original static SPA file.\n if (rr.reqHeader('x-ssr-browser') === 'playwright') {\n return true;\n }\n\n if (rr.reqIsMethod(HttpMethod.GET) && rr.reqHasContentTypeHeader(Mimes.TextHtml)) {\n // Build target URL for Playwright to visit\n // Use the server's actual listening address and port if available\n const protocol = app.option.protocol || 'http';\n const host = app.option.hostname || '127.0.0.1';\n const port = app.option.port || 80;\n\n const url = rr.reqUrlObj({ host: `${host}:${port}` });\n url.protocol = protocol;\n\n const targetUrl = url.toString() ?? this.welcomUrl;\n\n if (!this.browser) {\n console.error('Playwright browser is not initialized. Bypassing SSR.');\n return true;\n }\n\n // Create a fresh context for isolation\n // IMPORTANT: We do NOT use `extraHTTPHeaders` globally because it attaches the header to EVERY request\n // Playwright makes (including CORS requests to FontAwesome or API requests).\n // Instead, we will set the header ONLY for the initial navigation request to our server.\n const context = await this.browser.newContext();\n const page = await context.newPage();\n\n try {\n // Intercept ONLY requests going to our local server and append the bypass header\n await page.route('**/*', route => {\n const request = route.request();\n\n // Only append the x-ssr-browser header for requests to the local server that are NOT API requests\n const isLocal = request.url().startsWith(targetUrl) || request.url().includes('localhost') || request.url().includes('127.0.0.1');\n const isApi = request.url().includes('/api/');\n\n if (isLocal && !isApi) {\n const headers = {\n ...request.headers(),\n 'x-ssr-browser': 'playwright'\n };\n route.continue({ headers }).catch(() => {});\n } else {\n // For external requests (like font-awesome CORS) or API calls, do not add the custom header\n route.continue().catch(() => {});\n }\n });\n\n // 3. Navigate to the page and wait for the framework to finish rendering\n // but normally Playwright just navigates to the targetUrl and loads the real SPA resources.\n\n // \uD83D\uDCA1 Playwright \u2194 Framework \uD1B5\uC2E0 \uC124\uC815\n // \uD504\uB860\uD2B8\uC5D4\uB4DC\uC758 `bootfactory.ts` \uC548\uC758 `onRouteChanged` \uB4F1\uC5D0\uC11C\n // `if (window.onPlaywrightReady) window.onPlaywrightReady()` \uB77C\uACE0 \uD638\uCD9C\uD574\uC8FC\uBA74,\n // \uC544\uB798\uC758 Promise\uAC00 \uC989\uC2DC resolve \uB418\uB3C4\uB85D \uC5F0\uACB0\uD569\uB2C8\uB2E4.\n let resolvePlaywrightReady: () => void;\n const playwrightReadyPromise = new Promise<void>(resolve => {\n resolvePlaywrightReady = resolve;\n });\n\n await page.exposeFunction('onPlaywrightReady', () => {\n console.log('\u26A1\uFE0F [SSR:Playwright] Received \"onPlaywrightReady\" signal from framework!');\n resolvePlaywrightReady();\n });\n\n // 3. Navigate to the page and wait for the framework to finish rendering\n // Since the server will return the `index.html` (due to the bypass header), Playwright will download\n // your main.js / bundle.js, evaluate it, and the Custom Elements will register themselves naturally!\n await page.goto(targetUrl, {\n waitUntil: this.config.playwright?.waitUntil ?? 'networkidle',\n timeout: this.config.playwright?.timeout ?? 15000\n });\n\n // \uD83D\uDCA1 Framework Load Wait (Crucial for SWC)\n // Wait for EITHER the framework to call `window.onPlaywrightReady()` OR a specific innerHTML condition\n await Promise.race([\n playwrightReadyPromise, // \uC9C1\uC811 exposeFunction\uC5D0\uC11C \uD2B8\uB9AC\uAC70\uB41C Promise\n\n page.waitForFunction(\n () => {\n // Fallback 1: If explicit signal variable is set\n return (window as any)._playwrightReadySignalFired === true;\n },\n { timeout: this.config.playwright?.timeout ?? 15000 }\n ),\n\n page.waitForFunction(\n () => {\n // Fallback 2: If no signal, just wait until body has content\n return document.body.innerHTML.trim().length > 100;\n },\n { timeout: this.config.playwright?.timeout ?? 15000 }\n )\n ]).catch(() => console.log('Wait for app mount timeout... proceeding anyway'));\n\n // \uAC15\uC81C\uB85C \uCEF4\uD3EC\uB10C\uD2B8 \uB80C\uB354\uB9C1 \uBC0F \uD3F0\uD2B8\uC5B4\uC378 \uB4F1 \uB9AC\uC18C\uC2A4 \uB85C\uB529 \uB300\uAE30 \uC2DC\uAC04 \uCD94\uAC00 (\uC548\uC804 \uC7A5\uCE58)\n // onPlaywrightReady \uC2E0\uD638\uAC00 \uB5A8\uC5B4\uC838\uB3C4, \uBE44\uB3D9\uAE30 \uB80C\uB354\uB9C1(SwcLoop \uB4F1)\uC774 DOM\uC5D0 \uC644\uC804\uD788 \uBC18\uC601\uB418\uB294 \uB370\n // \uC57D\uAC04\uC758 Microtask \uC9C0\uC5F0\uC774 \uC788\uC744 \uC218 \uC788\uC73C\uBBC0\uB85C \uC544\uC8FC \uC9E7\uAC8C\uB9CC \uAE30\uB2E4\uB824 \uC90D\uB2C8\uB2E4.\n // await new Promise(resolve => setTimeout(resolve, 300));\n\n // Optional: Wait for a specific component to be visible\n if (this.config.playwright?.waitForSelector) {\n await page.waitForSelector(this.config.playwright.waitForSelector, {\n timeout: this.config.playwright?.timeout ?? 15000\n });\n }\n\n // Optional: Hardcoded wait time if explicitly set (fallback)\n if (this.config.playwright?.waitForTimeout) {\n await page.waitForTimeout(this.config.playwright.waitForTimeout);\n }\n\n // 4. Set SSR Attribute before extracting HTML\n await page.evaluate(() => {\n document.body.setAttribute('ssr-use', 'true');\n });\n\n // 5. Generate Final HTML\n const html = await page.evaluate(ignoreTags => {\n const skipTags = new Set(ignoreTags || []);\n\n function serializeNode(node: Node, inBody: boolean = false): string {\n if (node.nodeType === Node.TEXT_NODE) {\n const text = node.textContent || '';\n return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n }\n if (node.nodeType === Node.COMMENT_NODE) {\n return `<!--${node.textContent}-->`;\n }\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return '';\n }\n\n const el = node as Element;\n const tag = el.tagName.toLowerCase();\n const isBody = tag === 'body';\n const isInsideBody = inBody || isBody;\n\n // \uD83D\uDEAB Skip ignored tags (like <style>) ONLY if we are inside the <body>.\n // This ensures <style> tags in the <head> (global styles) are preserved!\n if (isInsideBody && skipTags.has(tag)) {\n return '';\n }\n\n let s = `<${tag}`;\n\n // 1. Serialize Attributes\n for (let i = 0; i < el.attributes.length; i++) {\n const attr = el.attributes[i];\n s += ` ${attr.name}=\"${attr.value.replace(/\"/g, '&quot;')}\"`;\n }\n\n // Handle void elements (self-closing)\n const voidElements = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);\n if (voidElements.has(tag)) {\n s += '>';\n return s;\n }\n s += '>';\n\n // 2. Serialize Shadow DOM (Declarative Shadow DOM)\n // MUST KEEP for SSR: Without this, the user receives an empty shell until JS loads and re-renders everything.\n // This allows the browser to paint the full UI (including styles inside the component) immediately.\n if (el.shadowRoot) {\n s += `<template shadowrootmode=\"${el.shadowRoot.mode}\">`;\n for (let i = 0; i < el.shadowRoot.childNodes.length; i++) {\n s += serializeNode(el.shadowRoot.childNodes[i], isInsideBody);\n }\n s += '</template>';\n }\n\n // 3. Serialize Light DOM Children\n for (let i = 0; i < el.childNodes.length; i++) {\n s += serializeNode(el.childNodes[i], isInsideBody);\n }\n\n s += `</${tag}>`;\n return s;\n }\n\n let result = '<!DOCTYPE html>\\n<html';\n const htmlNode = document.documentElement;\n for (let i = 0; i < htmlNode.attributes.length; i++) {\n const attr = htmlNode.attributes[i];\n result += ` ${attr.name}=\"${attr.value.replace(/\"/g, '&quot;')}\"`;\n }\n result += '>\\n';\n\n if (document.head) result += serializeNode(document.head, false);\n result += '\\n';\n if (document.body) result += serializeNode(document.body, true);\n\n result += '\\n</html>';\n return result;\n }, this.config.playwright?.ignoreTags || []);\n console.log(`\uD83D\uDC88 [SSR:Playwright] Successfully rendered ${targetUrl}`);\n\n await this.writeOkHtmlAndEnd({ rr }, this.makeHTML(html));\n } catch (e) {\n console.error(`Playwright SSR Error for ${targetUrl}:`, e);\n // If Playwright fails (e.g., timeout), we bypass SSR so the client at least gets the CSR app\n return true;\n } finally {\n await context.close();\n }\n return false; // Tell SimpleBootHttpServer to stop routing because we've handled the response\n }\n return true;\n }\n\n makeHTML(html: string) {\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
5
  "mappings": "AACA,SAAS,mBAAmB;AAE5B,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAI3B,SAAQ,kBAAiB;AAoClB,MAAM,4BAA8C;AAAA,EAIzD,YAAmB,QAAsB;AAAtB;AAHnB,SAAQ,YAAY;AAIlB,SAAK,YAAY,OAAO,aAAa,KAAK;AAAA,EAC5C;AAAA,EAEA,MAAM,OAAO,KAA2B;AAEtC,UAAM,EAAE,SAAS,IA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