@deepkit/angular-ssr 1.0.1 → 1.0.3
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/CHANGELOG.md +10 -0
- package/README.md +19 -16
- package/dist/cjs/src/angular.d.ts +10 -3
- package/dist/cjs/src/angular.js +29 -19
- package/dist/cjs/src/angular.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/angular.d.ts +10 -3
- package/dist/esm/src/angular.js +29 -19
- package/dist/esm/src/angular.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/angular.ts +23 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepkit/angular-ssr",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Deepkit + angular SSR",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@angular/ssr": "^19.1.6",
|
|
28
|
-
"@deepkit/app": "^1.0.1
|
|
29
|
-
"@deepkit/http": "^1.0.1
|
|
28
|
+
"@deepkit/app": "^1.0.1",
|
|
29
|
+
"@deepkit/http": "^1.0.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@angular/ssr": "^19.1.7",
|
|
33
|
-
"@deepkit/app": "^1.0.
|
|
34
|
-
"@deepkit/http": "^1.0.
|
|
33
|
+
"@deepkit/app": "^1.0.3",
|
|
34
|
+
"@deepkit/http": "^1.0.3"
|
|
35
35
|
},
|
|
36
36
|
"jest": {
|
|
37
37
|
"transform": {
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"**/tests/**/*.spec.ts"
|
|
45
45
|
]
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "7d79494280d022103f626dd7760bed8d6d66caa9"
|
|
48
48
|
}
|
package/src/angular.ts
CHANGED
|
@@ -47,6 +47,11 @@ class AngularConfig {
|
|
|
47
47
|
* @see REQUEST_CONTEXT
|
|
48
48
|
*/
|
|
49
49
|
serverBaseUrl: string = '';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Value of `import.meta.url` in the main entry point module (usually app.ts/server.ts).
|
|
53
|
+
*/
|
|
54
|
+
moduleUrl: string = '';
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
/**
|
|
@@ -62,26 +67,27 @@ class AngularRequestContext {
|
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
|
|
65
|
-
|
|
70
|
+
class AngularState {
|
|
71
|
+
ngApp: AngularNodeAppEngine = new AngularNodeAppEngine()
|
|
72
|
+
}
|
|
66
73
|
|
|
67
74
|
class AngularListener {
|
|
68
75
|
constructor(
|
|
69
76
|
public requestContext: AngularRequestContext,
|
|
77
|
+
public state: AngularState,
|
|
70
78
|
) {
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
@eventDispatcher.listen(httpWorkflow.onRoute, 102) //102 after 101=static listener, 100=default listener
|
|
74
82
|
async onRoute(event: typeof httpWorkflow.onRoute.event) {
|
|
75
83
|
if (event.route) return; //already found
|
|
76
|
-
if (!_ngApp) return;
|
|
77
84
|
|
|
78
|
-
const promise =
|
|
85
|
+
const promise = this.state.ngApp.handle(event.request, this.requestContext);
|
|
79
86
|
if (!promise) return;
|
|
80
87
|
|
|
81
88
|
event.routeFound(new RouteConfig('angular', ['GET'], event.request.url || '', {
|
|
82
89
|
type: 'function',
|
|
83
90
|
fn: async (req: HttpRequest, res: HttpResponse) => {
|
|
84
|
-
if (!_ngApp) return;
|
|
85
91
|
const response = await promise;
|
|
86
92
|
if (!response) {
|
|
87
93
|
throw new HttpNotFoundError();
|
|
@@ -99,6 +105,12 @@ class AngularStaticListener {
|
|
|
99
105
|
public localPath: string = '';
|
|
100
106
|
public path: string = '/'; //public path
|
|
101
107
|
|
|
108
|
+
constructor(
|
|
109
|
+
protected config: AngularConfig,
|
|
110
|
+
) {
|
|
111
|
+
this.localPath = resolve(dirname(fileURLToPath(this.config.moduleUrl)), '../browser');
|
|
112
|
+
}
|
|
113
|
+
|
|
102
114
|
@eventDispatcher.listen(httpWorkflow.onRoute, 101) //after default route listener at 100
|
|
103
115
|
onRoute(event: typeof httpWorkflow.onRoute.event) {
|
|
104
116
|
if (event.sent) return;
|
|
@@ -123,6 +135,7 @@ export class RequestHandler {
|
|
|
123
135
|
protected started: boolean = false;
|
|
124
136
|
|
|
125
137
|
constructor(
|
|
138
|
+
protected config: AngularConfig,
|
|
126
139
|
protected logger: Logger,
|
|
127
140
|
protected requestContext: AngularRequestContext,
|
|
128
141
|
protected http: HttpKernel,
|
|
@@ -131,19 +144,17 @@ export class RequestHandler {
|
|
|
131
144
|
) {
|
|
132
145
|
}
|
|
133
146
|
|
|
134
|
-
create(
|
|
135
|
-
this.staticListener.localPath = resolve(dirname(fileURLToPath(url)), '../browser');
|
|
136
|
-
|
|
147
|
+
create(): NodeRequestHandlerFunction {
|
|
137
148
|
const global = ((globalThis as any).deepkitAngular ||= {}) as {
|
|
138
149
|
server?: ApplicationServer,
|
|
139
150
|
started?: boolean,
|
|
140
151
|
};
|
|
141
152
|
|
|
142
153
|
const waitForClose = global.server ? global.server.close() : Promise.resolve();
|
|
143
|
-
|
|
154
|
+
const mainModule = isMainModule(this.config.moduleUrl);
|
|
144
155
|
|
|
145
156
|
// We only listen for process signals in the main module.
|
|
146
|
-
const listenOnSignals =
|
|
157
|
+
const listenOnSignals = mainModule;
|
|
147
158
|
global.server = this.server;
|
|
148
159
|
|
|
149
160
|
const waitBootstrap = waitForClose.then(() => this.server.start({
|
|
@@ -157,7 +168,7 @@ export class RequestHandler {
|
|
|
157
168
|
this.requestContext.serverBaseUrl = `http://${host}`;
|
|
158
169
|
|
|
159
170
|
if (!this.requestContext.serverBaseUrl) {
|
|
160
|
-
if (
|
|
171
|
+
if (mainModule) {
|
|
161
172
|
this.requestContext.serverBaseUrl = 'http://localhost:8080';
|
|
162
173
|
} else {
|
|
163
174
|
//angular dev server
|
|
@@ -200,11 +211,13 @@ export class AngularModule extends createModuleClass({
|
|
|
200
211
|
RequestHandler,
|
|
201
212
|
AngularRequestContext,
|
|
202
213
|
AngularStaticListener,
|
|
214
|
+
AngularState,
|
|
203
215
|
],
|
|
204
216
|
exports: [
|
|
205
217
|
RequestHandler,
|
|
206
218
|
AngularRequestContext,
|
|
207
219
|
AngularStaticListener,
|
|
220
|
+
AngularState,
|
|
208
221
|
],
|
|
209
222
|
listeners: [
|
|
210
223
|
AngularListener,
|