@dooboostore/simple-boot-http-server-ssr 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -0
- package/dist/cjs/SimpleBootHttpSSRServer.js.map +2 -2
- package/dist/cjs/bundle-entry.js +46 -14
- package/dist/cjs/bundle-entry.js.map +2 -2
- package/dist/cjs/filters/SSRDomParserFilter.js +4 -3
- package/dist/cjs/filters/SSRDomParserFilter.js.map +2 -2
- package/dist/cjs/filters/SSRFilter.js +4 -3
- package/dist/cjs/filters/SSRFilter.js.map +2 -2
- package/dist/cjs/filters/{SSRLinkDomDomFilter.js → SSRLinkDomFilter.js} +11 -10
- package/dist/cjs/filters/SSRLinkDomFilter.js.map +7 -0
- package/dist/cjs/filters/SSRSimpleWebComponentDomParserFilter.js +81 -0
- package/dist/cjs/filters/SSRSimpleWebComponentDomParserFilter.js.map +7 -0
- package/dist/cjs/filters/SSRSimpleWebComponentFilter.js +158 -28
- package/dist/cjs/filters/SSRSimpleWebComponentFilter.js.map +2 -2
- package/dist/cjs/filters/index.js +9 -3
- package/dist/cjs/filters/index.js.map +2 -2
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/SimpleBootHttpSSRServer.js.map +2 -2
- package/dist/esm/bundle-entry.js +22 -7
- package/dist/esm/bundle-entry.js.map +2 -2
- package/dist/esm/filters/SSRDomParserFilter.js +5 -4
- package/dist/esm/filters/SSRDomParserFilter.js.map +2 -2
- package/dist/esm/filters/SSRFilter.js +4 -3
- package/dist/esm/filters/SSRFilter.js.map +2 -2
- package/dist/esm/filters/{SSRLinkDomDomFilter.js → SSRLinkDomFilter.js} +7 -6
- package/dist/esm/filters/SSRLinkDomFilter.js.map +7 -0
- package/dist/esm/filters/SSRSimpleWebComponentDomParserFilter.js +58 -0
- package/dist/esm/filters/SSRSimpleWebComponentDomParserFilter.js.map +7 -0
- package/dist/esm/filters/SSRSimpleWebComponentFilter.js +148 -28
- package/dist/esm/filters/SSRSimpleWebComponentFilter.js.map +2 -2
- package/dist/esm/filters/index.js +4 -1
- package/dist/esm/filters/index.js.map +2 -2
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js +57949 -20024
- package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js.map +4 -4
- package/dist/types/SimpleBootHttpSSRServer.d.ts +1 -1
- package/dist/types/SimpleBootHttpSSRServer.d.ts.map +1 -1
- package/dist/types/bundle-entry.d.ts +11 -7
- package/dist/types/bundle-entry.d.ts.map +1 -1
- package/dist/types/filters/SSRDomParserFilter.d.ts +3 -3
- package/dist/types/filters/SSRDomParserFilter.d.ts.map +1 -1
- package/dist/types/filters/SSRFilter.d.ts.map +1 -1
- package/dist/types/filters/{SSRLinkDomDomFilter.d.ts → SSRLinkDomFilter.d.ts} +5 -5
- package/dist/types/filters/SSRLinkDomFilter.d.ts.map +1 -0
- package/dist/types/filters/SSRSimpleWebComponentDomParserFilter.d.ts +37 -0
- package/dist/types/filters/SSRSimpleWebComponentDomParserFilter.d.ts.map +1 -0
- package/dist/types/filters/SSRSimpleWebComponentFilter.d.ts +23 -3
- package/dist/types/filters/SSRSimpleWebComponentFilter.d.ts.map +1 -1
- package/dist/types/filters/index.d.ts +4 -1
- package/dist/types/filters/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js +58543 -20621
- package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js.map +4 -4
- package/package.json +20 -19
- package/src/SimpleBootHttpSSRServer.ts +2 -3
- package/src/bundle-entry.ts +16 -7
- package/src/filters/SSRDomParserFilter.ts +9 -8
- package/src/filters/SSRFilter.ts +4 -3
- package/src/filters/{SSRLinkDomDomFilter.ts → SSRLinkDomFilter.ts} +7 -6
- package/src/filters/SSRSimpleWebComponentDomParserFilter.ts +106 -0
- package/src/filters/SSRSimpleWebComponentFilter.ts +242 -39
- package/src/filters/index.ts +5 -2
- package/src/index.ts +0 -1
- package/README.MD +0 -167
- package/dist/cjs/decorators/LoadAroundBefore.js +0 -54
- package/dist/cjs/decorators/LoadAroundBefore.js.map +0 -7
- package/dist/cjs/decorators/SaveAroundAfter.js +0 -53
- package/dist/cjs/decorators/SaveAroundAfter.js.map +0 -7
- package/dist/cjs/decorators/index.js +0 -24
- package/dist/cjs/decorators/index.js.map +0 -7
- package/dist/cjs/filters/SSRLinkDomDomFilter.js.map +0 -7
- package/dist/esm/decorators/LoadAroundBefore.js +0 -31
- package/dist/esm/decorators/LoadAroundBefore.js.map +0 -7
- package/dist/esm/decorators/SaveAroundAfter.js +0 -29
- package/dist/esm/decorators/SaveAroundAfter.js.map +0 -7
- package/dist/esm/decorators/index.js +0 -3
- package/dist/esm/decorators/index.js.map +0 -7
- package/dist/esm/filters/SSRLinkDomDomFilter.js.map +0 -7
- package/dist/types/decorators/LoadAroundBefore.d.ts +0 -2
- package/dist/types/decorators/LoadAroundBefore.d.ts.map +0 -1
- package/dist/types/decorators/SaveAroundAfter.d.ts +0 -3
- package/dist/types/decorators/SaveAroundAfter.d.ts.map +0 -1
- package/dist/types/decorators/index.d.ts +0 -3
- package/dist/types/decorators/index.d.ts.map +0 -1
- package/dist/types/filters/SSRLinkDomDomFilter.d.ts.map +0 -1
- package/src/decorators/LoadAroundBefore.ts +0 -28
- package/src/decorators/SaveAroundAfter.ts +0 -27
- package/src/decorators/index.ts +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dooboostore/simple-boot-http-server-ssr",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -67,10 +67,18 @@
|
|
|
67
67
|
"url": "https://github.com/dooboostore-develop/packages"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"reflect-metadata": "^0.2.2"
|
|
70
|
+
"reflect-metadata": "^0.2.2",
|
|
71
|
+
"@dooboostore/core": "1.0.32",
|
|
72
|
+
"@dooboostore/dom-render": "1.0.114",
|
|
73
|
+
"@dooboostore/dom-parser": "1.0.7",
|
|
74
|
+
"@dooboostore/core-node": "1.0.13",
|
|
75
|
+
"@dooboostore/simple-boot-front": "1.0.132",
|
|
76
|
+
"@dooboostore/core-web": "1.0.13",
|
|
77
|
+
"@dooboostore/simple-boot": "1.0.57",
|
|
78
|
+
"@dooboostore/simple-web-component": "1.0.47",
|
|
79
|
+
"@dooboostore/simple-boot-http-server": "1.0.26"
|
|
71
80
|
},
|
|
72
81
|
"devDependencies": {
|
|
73
|
-
"@types/jsdom": "^21.1.7",
|
|
74
82
|
"@babel/core": "^7.24.0",
|
|
75
83
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
76
84
|
"@babel/plugin-proposal-decorators": "^7.24.0",
|
|
@@ -78,28 +86,21 @@
|
|
|
78
86
|
"@babel/preset-env": "^7.24.0",
|
|
79
87
|
"@babel/preset-typescript": "^7.24.0",
|
|
80
88
|
"@types/jest": "^26.0.22",
|
|
81
|
-
"
|
|
82
|
-
"@typescript-eslint/eslint-plugin": "^4.16.1",
|
|
83
|
-
"@typescript-eslint/parser": "^4.16.1",
|
|
84
|
-
"tslib": "^2.8.1",
|
|
89
|
+
"@types/jsdom": "^21.1.7",
|
|
85
90
|
"@types/node": "^20",
|
|
86
|
-
"typescript": "^5.9.2",
|
|
87
91
|
"@types/node-gzip": "^1.1.0",
|
|
88
|
-
"
|
|
92
|
+
"@typescript-eslint/eslint-plugin": "^4.16.1",
|
|
93
|
+
"@typescript-eslint/parser": "^4.16.1",
|
|
89
94
|
"esbuild": "^0.23.0",
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"@dooboostore/simple-boot-front": "1.0.131",
|
|
95
|
-
"@dooboostore/simple-boot-http-server": "1.0.24",
|
|
96
|
-
"@dooboostore/dom-parser": "1.0.5",
|
|
97
|
-
"@dooboostore/simple-boot": "1.0.54",
|
|
98
|
-
"@dooboostore/dom-render": "1.0.113"
|
|
95
|
+
"esbuild-plugin-tsc": "^0.5.0",
|
|
96
|
+
"raw-loader": "^4.0.2",
|
|
97
|
+
"tslib": "^2.8.1",
|
|
98
|
+
"typescript": "^5.9.2"
|
|
99
99
|
},
|
|
100
100
|
"dependencies": {
|
|
101
101
|
"jsdom": "^26.0.0",
|
|
102
|
-
"linkedom": "0.18.12"
|
|
102
|
+
"linkedom": "0.18.12",
|
|
103
|
+
"playwright": "^1.59.1"
|
|
103
104
|
},
|
|
104
105
|
"scripts": {
|
|
105
106
|
"clean": "rm -rf dist",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';
|
|
2
|
-
// import { SimstanceManager } from '@dooboostore/simple-boot/simstance/SimstanceManager';
|
|
3
2
|
import { HttpSSRServerOption } from './option/HttpSSRServerOption';
|
|
4
3
|
import { ConstructorType } from '@dooboostore/core';
|
|
5
4
|
import {SimConfig} from "@dooboostore/simple-boot/decorators/SimDecorator";
|
|
@@ -9,8 +8,8 @@ export class SimpleBootHttpSSRServer extends SimpleBootHttpServer {
|
|
|
9
8
|
super(option)
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
run(otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig |
|
|
13
|
-
const oi = new Map<ConstructorType<any> | Function | SimConfig |
|
|
11
|
+
run(otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>) {
|
|
12
|
+
const oi = new Map<ConstructorType<any> | Function | SimConfig | symbol, any>();
|
|
14
13
|
oi.set(SimpleBootHttpSSRServer, this);
|
|
15
14
|
otherInstanceSim?.forEach((value, key) => oi.set(key, value));
|
|
16
15
|
return super.run(oi);
|
package/src/bundle-entry.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from './
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
|
|
3
|
+
// simple-boot-http-server-ssr itself
|
|
4
|
+
export * from './index';
|
|
5
|
+
|
|
6
|
+
// Re-export peer dependencies so bundle consumers can access them
|
|
7
|
+
// without separately importing each package
|
|
8
|
+
export * as Core from '@dooboostore/core';
|
|
9
|
+
export * as CoreNode from '@dooboostore/core-node';
|
|
10
|
+
export * as CoreWeb from '@dooboostore/core-web';
|
|
11
|
+
export * as DomParser from '@dooboostore/dom-parser';
|
|
12
|
+
export * as DomRender from '@dooboostore/dom-render';
|
|
13
|
+
export * as SimpleBoot from '@dooboostore/simple-boot';
|
|
14
|
+
export * as SimpleBootFront from '@dooboostore/simple-boot-front';
|
|
15
|
+
export * as SimpleBootHttpServer from '@dooboostore/simple-boot-http-server';
|
|
16
|
+
export * as SimpleWebComponent from '@dooboostore/simple-web-component';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';
|
|
2
2
|
import { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';
|
|
3
3
|
import { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';
|
|
4
|
-
import { ConstructorType, AsyncBlockingQueue, RandomUtils,
|
|
4
|
+
import { ConstructorType, AsyncBlockingQueue, RandomUtils, firstValueFrom } from '@dooboostore/core';
|
|
5
|
+
import { filter, first } from '@dooboostore/core/message/operators';
|
|
5
6
|
import { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';
|
|
6
7
|
import { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';
|
|
7
8
|
import { HttpStatus } from '@dooboostore/simple-boot-http-server/codes/HttpStatus';
|
|
@@ -16,7 +17,7 @@ import { DomParserInitializer } from '../initializers/DomParserInitializer';
|
|
|
16
17
|
import { JsdomInitializer } from '../initializers';
|
|
17
18
|
import { SimConfig } from '@dooboostore/simple-boot/decorators/SimDecorator';
|
|
18
19
|
|
|
19
|
-
export type
|
|
20
|
+
export type DomParserFactoryAndParams = {
|
|
20
21
|
frontDistPath: string;
|
|
21
22
|
frontDistIndexFileName?: string;
|
|
22
23
|
factorySimFrontOption: (window: any) => SimFrontOption;
|
|
@@ -43,7 +44,7 @@ export class SSRDomParserFilter implements Filter {
|
|
|
43
44
|
// private intervalId?: NodeJS.Timeout;
|
|
44
45
|
|
|
45
46
|
constructor(
|
|
46
|
-
public config:
|
|
47
|
+
public config: DomParserFactoryAndParams,
|
|
47
48
|
public otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | Symbol, any>
|
|
48
49
|
) {
|
|
49
50
|
config.frontDistIndexFileName = config.frontDistIndexFileName || 'index.html';
|
|
@@ -97,10 +98,10 @@ export class SSRDomParserFilter implements Filter {
|
|
|
97
98
|
const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));
|
|
98
99
|
const domExcludes = [RequestResponse, ...(this.config.domExcludes || [])];
|
|
99
100
|
const simpleBootFront = await this.config.factory.create(option, this.config.using, domExcludes);
|
|
100
|
-
otherInstanceSim ??= new Map<Function | ConstructorType<any> | SimConfig |
|
|
101
|
+
otherInstanceSim ??= new Map<Function | ConstructorType<any> | SimConfig | symbol, any>();
|
|
101
102
|
this.otherInstanceSim?.forEach((v, k) => otherInstanceSim!.set(k, v));
|
|
102
103
|
|
|
103
|
-
simpleBootFront.run(otherInstanceSim);
|
|
104
|
+
simpleBootFront.run(otherInstanceSim as any);
|
|
104
105
|
// (simpleBootFront as any).generation = this.poolGeneration;
|
|
105
106
|
return simpleBootFront;
|
|
106
107
|
}
|
|
@@ -144,15 +145,15 @@ export class SSRDomParserFilter implements Filter {
|
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
const data = await
|
|
148
|
+
const data = await firstValueFrom(
|
|
148
149
|
simpleBootFront.routingObservable.pipe(
|
|
149
|
-
|
|
150
|
+
filter(it => {
|
|
150
151
|
|
|
151
152
|
const sw = it.triggerPoint === 'end' && typeof it.routerModule.intent.uri === 'string' && targetUrl.endsWith(it.routerModule.intent.uri);
|
|
152
153
|
return sw;
|
|
153
154
|
}),
|
|
154
155
|
// delay(1000),
|
|
155
|
-
|
|
156
|
+
first()
|
|
156
157
|
)
|
|
157
158
|
);
|
|
158
159
|
|
package/src/filters/SSRFilter.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';
|
|
2
2
|
import { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';
|
|
3
3
|
import { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';
|
|
4
|
-
import { ConstructorType, AsyncBlockingQueue, RandomUtils,
|
|
4
|
+
import { ConstructorType, AsyncBlockingQueue, RandomUtils, firstValueFrom } from '@dooboostore/core';
|
|
5
|
+
import { first } from '@dooboostore/core/message/operators';
|
|
5
6
|
import { JsdomInitializer } from '../initializers/JsdomInitializer';
|
|
6
7
|
import { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';
|
|
7
8
|
import { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';
|
|
@@ -162,7 +163,7 @@ export class SSRFilter implements Filter {
|
|
|
162
163
|
// // delay(1000),
|
|
163
164
|
// first()
|
|
164
165
|
// );
|
|
165
|
-
const data = await
|
|
166
|
+
const data = await firstValueFrom(
|
|
166
167
|
// @ts-ignore
|
|
167
168
|
simpleBootFront.routingObservable.pipe(
|
|
168
169
|
// @ts-ignore
|
|
@@ -173,7 +174,7 @@ export class SSRFilter implements Filter {
|
|
|
173
174
|
targetUrl.endsWith(it.routerModule.intent.uri)
|
|
174
175
|
),
|
|
175
176
|
// delay(1000),
|
|
176
|
-
|
|
177
|
+
first()
|
|
177
178
|
)
|
|
178
179
|
);
|
|
179
180
|
// console.log('rrrrrssss');
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';
|
|
2
2
|
import { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';
|
|
3
3
|
import { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';
|
|
4
|
-
import { ConstructorType, AsyncBlockingQueue, RandomUtils,
|
|
4
|
+
import { ConstructorType, AsyncBlockingQueue, RandomUtils, firstValueFrom } from '@dooboostore/core';
|
|
5
|
+
import { first } from '@dooboostore/core/message/operators';
|
|
5
6
|
import { JsdomInitializer } from '../initializers/JsdomInitializer';
|
|
6
7
|
import { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';
|
|
7
8
|
import { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';
|
|
@@ -15,7 +16,7 @@ import { DomRenderProxy } from '@dooboostore/dom-render';
|
|
|
15
16
|
import { parseHTML } from 'linkedom';
|
|
16
17
|
import { LinkedomInitializer } from '../initializers/LinkedomInitializer';
|
|
17
18
|
|
|
18
|
-
export type
|
|
19
|
+
export type LinkDomFactoryAndParams = {
|
|
19
20
|
frontDistPath: string;
|
|
20
21
|
frontDistIndexFileName?: string;
|
|
21
22
|
factorySimFrontOption: (window: any) => SimFrontOption;
|
|
@@ -33,7 +34,7 @@ export type FactoryAndParams = {
|
|
|
33
34
|
};
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
export class
|
|
37
|
+
export class SSRLinkDomFilter implements Filter {
|
|
37
38
|
private simpleBootFrontPool: SimpleBootFront[] = [];
|
|
38
39
|
private simpleBootFrontQueue = new AsyncBlockingQueue<SimpleBootFront>();
|
|
39
40
|
// private indexHTML: string;
|
|
@@ -42,7 +43,7 @@ export class SSRLinkDomDomFilter implements Filter {
|
|
|
42
43
|
private intervalId?: NodeJS.Timeout;
|
|
43
44
|
|
|
44
45
|
constructor(
|
|
45
|
-
public config:
|
|
46
|
+
public config: LinkDomFactoryAndParams,
|
|
46
47
|
public otherInstanceSim?: Map<ConstructorType<any>, any>
|
|
47
48
|
) {
|
|
48
49
|
config.frontDistIndexFileName = config.frontDistIndexFileName || 'index.html';
|
|
@@ -142,7 +143,7 @@ export class SSRLinkDomDomFilter implements Filter {
|
|
|
142
143
|
// }
|
|
143
144
|
// })
|
|
144
145
|
|
|
145
|
-
const data = await
|
|
146
|
+
const data = await firstValueFrom(
|
|
146
147
|
// @ts-ignore
|
|
147
148
|
simpleBootFront.routingObservable.pipe(
|
|
148
149
|
// @ts-ignore
|
|
@@ -153,7 +154,7 @@ export class SSRLinkDomDomFilter implements Filter {
|
|
|
153
154
|
targetUrl.endsWith(it.routerModule.intent.uri)
|
|
154
155
|
),
|
|
155
156
|
// delay(1000),
|
|
156
|
-
|
|
157
|
+
first()
|
|
157
158
|
)
|
|
158
159
|
);
|
|
159
160
|
// console.log('???????done');
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {RequestResponse} from '@dooboostore/simple-boot-http-server/models/RequestResponse';
|
|
2
|
+
import {HttpHeaders} from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';
|
|
3
|
+
import {Filter} from '@dooboostore/simple-boot-http-server/filters/Filter';
|
|
4
|
+
import {Mimes} from '@dooboostore/simple-boot-http-server/codes/Mimes';
|
|
5
|
+
import {HttpStatus} from '@dooboostore/simple-boot-http-server/codes/HttpStatus';
|
|
6
|
+
import {SimpleBootHttpServer} from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';
|
|
7
|
+
import {DomParserInitializer} from '../initializers/DomParserInitializer';
|
|
8
|
+
|
|
9
|
+
export type SWCSSRDomParserConfig = {
|
|
10
|
+
frontDistPath: string;
|
|
11
|
+
frontDistIndexFileName?: string;
|
|
12
|
+
welcomUrl?: string;
|
|
13
|
+
ssrExcludeFilter?: (rr: RequestResponse) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Function to register components for each request.
|
|
16
|
+
*/
|
|
17
|
+
registerComponents?: (window: any) => Promise<void> | void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* SSR Filter specifically for Simple Web Component (SWC).
|
|
22
|
+
* It utilizes @dooboostore/dom-parser for rendering and DSD support.
|
|
23
|
+
*/
|
|
24
|
+
export class SSRSimpleWebComponentDomParserFilter implements Filter {
|
|
25
|
+
private welcomUrl = 'http://localhost';
|
|
26
|
+
|
|
27
|
+
constructor(public config: SWCSSRDomParserConfig) {
|
|
28
|
+
this.welcomUrl = config.welcomUrl || this.welcomUrl;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async onInit(app: SimpleBootHttpServer) {}
|
|
32
|
+
|
|
33
|
+
async onDestroy() {}
|
|
34
|
+
|
|
35
|
+
async proceedBefore({ rr }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {
|
|
36
|
+
if (this.config.ssrExcludeFilter?.(rr)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {
|
|
41
|
+
const url = rr.reqUrlObj({ host: 'localhost' });
|
|
42
|
+
const targetUrl = url.toString() ?? this.welcomUrl;
|
|
43
|
+
console.log('SSRSimpleWebComponentDomParserFilter start');
|
|
44
|
+
|
|
45
|
+
// 1. Initialize Virtual DOM Environment
|
|
46
|
+
const domParserInitializer = new DomParserInitializer(this.config.frontDistPath, this.config.frontDistIndexFileName || 'index.html', { url: targetUrl });
|
|
47
|
+
const window = await domParserInitializer.run();
|
|
48
|
+
|
|
49
|
+
// web component 경우 자기 tagName을 생성자 에게 HTMLElementBase에넘겨줘야되기떄문에
|
|
50
|
+
// const getTagName = (type: ConstructorType<any>) => {
|
|
51
|
+
// const zz = getElementConfig(type);
|
|
52
|
+
// return zz.name;
|
|
53
|
+
// };
|
|
54
|
+
// (window as any).HTMLElement = class extends HTMLElementBase {
|
|
55
|
+
// constructor(...args: any[]) {
|
|
56
|
+
// const ctor = new.target as any; // 이런 슈가 기능이...
|
|
57
|
+
// const resolvedTagName = getTagName(ctor);
|
|
58
|
+
// super(resolvedTagName, args[0]);
|
|
59
|
+
// }
|
|
60
|
+
// }
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
// 2. Register Components if provided
|
|
65
|
+
// We use SwcApplication inside the callback or directly here.
|
|
66
|
+
if (this.config.registerComponents) {
|
|
67
|
+
await this.config.registerComponents(window);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// window.document.querySelector('.sidebar-space').innerHTML = '씨발놈아.';
|
|
71
|
+
// await new Promise<void>((resolve, reject) => setTimeout(resolve, 100));
|
|
72
|
+
// await new Promise<void>((resolve, reject) => setTimeout(resolve, 5000));
|
|
73
|
+
// window.document.body.innerHTML = '';
|
|
74
|
+
// window.document.body.setAttribute('ssr-use', 'true');
|
|
75
|
+
// 3. Generate Final HTML
|
|
76
|
+
const html = this.makeHTML(window);
|
|
77
|
+
// console.log('html: 💈', html);
|
|
78
|
+
await this.writeOkHtmlAndEnd({ rr }, html);
|
|
79
|
+
} finally {
|
|
80
|
+
// 4. Cleanup
|
|
81
|
+
window.close();
|
|
82
|
+
domParserInitializer.destroy();
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
makeHTML(window: any) {
|
|
90
|
+
let html = window.document.documentElement.outerHTML;
|
|
91
|
+
if (!/^<!DOCTYPE html>/i.test(html)) {
|
|
92
|
+
html = '<!DOCTYPE html>\n' + html;
|
|
93
|
+
}
|
|
94
|
+
return html;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }: { rr: RequestResponse; status?: HttpStatus }, html: string) {
|
|
98
|
+
rr.resStatusCode(status);
|
|
99
|
+
rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);
|
|
100
|
+
await rr.resEnd(html);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async proceedAfter() {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|