@deepkit/angular-ssr 1.0.1-alpha.158
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 +19 -0
- package/LICENSE +21 -0
- package/README.md +119 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/src/angular.d.ts +58 -0
- package/dist/cjs/src/angular.js +228 -0
- package/dist/cjs/src/angular.js.map +1 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/src/angular.d.ts +58 -0
- package/dist/esm/src/angular.js +223 -0
- package/dist/esm/src/angular.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/index.ts +11 -0
- package/package.json +48 -0
- package/src/angular.ts +224 -0
- package/tsconfig.esm.json +15 -0
- package/tsconfig.json +38 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [1.0.1-alpha.158](https://github.com/deepkit/deepkit-framework/compare/v1.0.1-alpha.157...v1.0.1-alpha.158) (2025-02-15)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @deepkit/angular-ssr
|
|
9
|
+
|
|
10
|
+
## [1.0.1-alpha.157](https://github.com/deepkit/deepkit-framework/compare/v1.0.1-alpha.156...v1.0.1-alpha.157) (2025-02-15)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- **angular-ssr:** docs ([eae7291](https://github.com/deepkit/deepkit-framework/commit/eae729141372fc83492a9b66d479eb121eec7a0f))
|
|
15
|
+
- tsconfig and tsc build ([ac71e83](https://github.com/deepkit/deepkit-framework/commit/ac71e838d542a3cab0e9b1cfc20b27637f1c01df))
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
- update to angular 19 and typescript 5.7.3, new @deepkit/angular-ssr package ([#627](https://github.com/deepkit/deepkit-framework/issues/627)) ([52333a7](https://github.com/deepkit/deepkit-framework/commit/52333a71f98c7e25a74f048dd57f1efba61098f5))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Marc J. Schmidt <marc@marcjschmidt.de>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Deepkit + Angular SSR
|
|
2
|
+
|
|
3
|
+
## Configure Deepkit App
|
|
4
|
+
|
|
5
|
+
- Make sure to put your main application inside `app.ts` and export the `App` instance:
|
|
6
|
+
|
|
7
|
+
In `src/server/app.ts`:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { App } from '@deepkit/app';
|
|
11
|
+
import { FrameworkModule } from '@deepkit/framework';
|
|
12
|
+
import { AngularModule } from '@deepkit/angular-ssr';
|
|
13
|
+
|
|
14
|
+
export const app = new App({
|
|
15
|
+
controllers: [
|
|
16
|
+
// your controllers
|
|
17
|
+
],
|
|
18
|
+
providers: [
|
|
19
|
+
// your providers
|
|
20
|
+
],
|
|
21
|
+
imports: [
|
|
22
|
+
new FrameworkModule({}),
|
|
23
|
+
new AngularModule()
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Create a `src/server/server.ts` and configure it in your `angular.json`:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"builder": "@angular-devkit/build-angular:application",
|
|
33
|
+
"options": {
|
|
34
|
+
"outputPath": "dist/app",
|
|
35
|
+
"index": "src/index.html",
|
|
36
|
+
"server": "src/main.server.ts",
|
|
37
|
+
"outputMode": "server",
|
|
38
|
+
"ssr": {
|
|
39
|
+
"entry": "src/server/server.ts"
|
|
40
|
+
},
|
|
41
|
+
"browser": "src/main.ts"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
In `src/server/server.ts`:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { app } from './app';
|
|
50
|
+
import { RequestHandler } from '@deepkit/angular-ssr';
|
|
51
|
+
import { AngularNodeAppEngine } from '@angular/ssr/node';
|
|
52
|
+
|
|
53
|
+
export const reqHandler = app.get(RequestHandler).create(import.meta.url, new AngularNodeAppEngine());
|
|
54
|
+
````
|
|
55
|
+
|
|
56
|
+
## Configure Angular App
|
|
57
|
+
|
|
58
|
+
In `app/app.config.ts` (client side):
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
@Injectable()
|
|
62
|
+
export class APIInterceptor implements HttpInterceptor {
|
|
63
|
+
constructor(@Inject('baseUrl') @Optional() private baseUrl: string) {
|
|
64
|
+
// In client build, `baseUrl` is empty and should be inferred from the current location.
|
|
65
|
+
// If this is not correct, you can simply define the `baseUrl` in the `providers` array of the `appConfig` object.
|
|
66
|
+
this.baseUrl = baseUrl || (typeof location !== 'undefined' ? location.origin : '');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
|
70
|
+
const apiReq = req.clone({ url: `${this.baseUrl}/${req.url}` });
|
|
71
|
+
return next.handle(apiReq);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const appConfig: ApplicationConfig = {
|
|
76
|
+
providers: [
|
|
77
|
+
{
|
|
78
|
+
provide: HTTP_INTERCEPTORS,
|
|
79
|
+
useClass: APIInterceptor,
|
|
80
|
+
multi: true,
|
|
81
|
+
},
|
|
82
|
+
// your other providers
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
In `app/app.server.config.ts` (server side):
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { appConfig } from './app.config';
|
|
91
|
+
|
|
92
|
+
const serverConfig: ApplicationConfig = {
|
|
93
|
+
providers: [
|
|
94
|
+
provideServerRendering(),
|
|
95
|
+
provideServerRouting([
|
|
96
|
+
{
|
|
97
|
+
path: '**',
|
|
98
|
+
renderMode: RenderMode.Server,
|
|
99
|
+
},
|
|
100
|
+
]),
|
|
101
|
+
{
|
|
102
|
+
provide: HTTP_TRANSFER_CACHE_ORIGIN_MAP,
|
|
103
|
+
deps: [REQUEST_CONTEXT],
|
|
104
|
+
useFactory(context: any) {
|
|
105
|
+
return { [context?.baseUrl]: context?.publicBaseUrl || '' };
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
provide: 'baseUrl',
|
|
110
|
+
deps: [REQUEST_CONTEXT],
|
|
111
|
+
useFactory: (context: any) => {
|
|
112
|
+
return context?.baseUrl || '';
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const config = mergeApplicationConfig(appConfig, serverConfig);
|
|
119
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/angular.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Deepkit Framework
|
|
4
|
+
* Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the MIT License.
|
|
8
|
+
*
|
|
9
|
+
* You should have received a copy of the MIT License along with this program.
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
23
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
__exportStar(require("./src/angular.js"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;AAEH,mDAAiC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AngularNodeAppEngine, NodeRequestHandlerFunction } from '@angular/ssr/node';
|
|
2
|
+
import { HttpKernel, httpWorkflow } from '@deepkit/http';
|
|
3
|
+
import { ApplicationServer } from '@deepkit/framework';
|
|
4
|
+
import { Logger } from '@deepkit/logger';
|
|
5
|
+
declare class AngularConfig {
|
|
6
|
+
/**
|
|
7
|
+
* This can be set map HTTP_TRANSFER_CACHE_ORIGIN_MAP
|
|
8
|
+
* via `REQUEST_CONTEXT`.
|
|
9
|
+
*
|
|
10
|
+
* @see REQUEST_CONTEXT
|
|
11
|
+
*/
|
|
12
|
+
publicBaseUrl: string;
|
|
13
|
+
/**
|
|
14
|
+
* This is the base URL in the server, which is used in the server context
|
|
15
|
+
* for SSR. This is auto-detected when not set.
|
|
16
|
+
*
|
|
17
|
+
* @see REQUEST_CONTEXT
|
|
18
|
+
*/
|
|
19
|
+
serverBaseUrl: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* This object is available angular providers as DI token `REQUEST_CONTEXT`.
|
|
23
|
+
*/
|
|
24
|
+
declare class AngularRequestContext {
|
|
25
|
+
serverBaseUrl: string;
|
|
26
|
+
publicBaseUrl: string;
|
|
27
|
+
constructor(config: AngularConfig);
|
|
28
|
+
}
|
|
29
|
+
declare class AngularStaticListener {
|
|
30
|
+
localPath: string;
|
|
31
|
+
path: string;
|
|
32
|
+
onRoute(event: typeof httpWorkflow.onRoute.event): Promise<unknown> | undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* This creates a request handler function for the Angular SSR server.
|
|
36
|
+
* It also starts ApplicationServer of Deepkit Framework to serve HTTP/RPC requests.
|
|
37
|
+
*
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { app } from './app';
|
|
40
|
+
* import { RequestHandler } from '@deepkit/angular-ssr';
|
|
41
|
+
*
|
|
42
|
+
* export const reqHandler = app.get(RequestHandler).create(import.meta.url);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class RequestHandler {
|
|
46
|
+
protected logger: Logger;
|
|
47
|
+
protected requestContext: AngularRequestContext;
|
|
48
|
+
protected http: HttpKernel;
|
|
49
|
+
protected server: ApplicationServer;
|
|
50
|
+
protected staticListener: AngularStaticListener;
|
|
51
|
+
protected started: boolean;
|
|
52
|
+
constructor(logger: Logger, requestContext: AngularRequestContext, http: HttpKernel, server: ApplicationServer, staticListener: AngularStaticListener);
|
|
53
|
+
create(url: string, ngApp: AngularNodeAppEngine): NodeRequestHandlerFunction;
|
|
54
|
+
}
|
|
55
|
+
declare const AngularModule_base: import("@deepkit/app").AppModuleClass<AngularConfig>;
|
|
56
|
+
export declare class AngularModule extends AngularModule_base {
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AngularModule = exports.RequestHandler = void 0;
|
|
13
|
+
function __assignType(fn, args) {
|
|
14
|
+
fn.__type = args;
|
|
15
|
+
return fn;
|
|
16
|
+
}
|
|
17
|
+
/*
|
|
18
|
+
* Deepkit Framework
|
|
19
|
+
* Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
|
|
20
|
+
*
|
|
21
|
+
* This program is free software: you can redistribute it and/or modify
|
|
22
|
+
* it under the terms of the MIT License.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the MIT License along with this program.
|
|
25
|
+
*/
|
|
26
|
+
const node_1 = require("@angular/ssr/node");
|
|
27
|
+
const http_1 = require("@deepkit/http");
|
|
28
|
+
const event_1 = require("@deepkit/event");
|
|
29
|
+
const app_1 = require("@deepkit/app");
|
|
30
|
+
const framework_1 = require("@deepkit/framework");
|
|
31
|
+
const logger_1 = require("@deepkit/logger");
|
|
32
|
+
const node_path_1 = require("node:path");
|
|
33
|
+
const node_url_1 = require("node:url");
|
|
34
|
+
class AngularConfig {
|
|
35
|
+
constructor() {
|
|
36
|
+
/**
|
|
37
|
+
* This can be set map HTTP_TRANSFER_CACHE_ORIGIN_MAP
|
|
38
|
+
* via `REQUEST_CONTEXT`.
|
|
39
|
+
*
|
|
40
|
+
* @see REQUEST_CONTEXT
|
|
41
|
+
*/
|
|
42
|
+
this.publicBaseUrl = '';
|
|
43
|
+
/**
|
|
44
|
+
* This is the base URL in the server, which is used in the server context
|
|
45
|
+
* for SSR. This is auto-detected when not set.
|
|
46
|
+
*
|
|
47
|
+
* @see REQUEST_CONTEXT
|
|
48
|
+
*/
|
|
49
|
+
this.serverBaseUrl = '';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
AngularConfig.__type = ['publicBaseUrl', function () { return ''; }, 'serverBaseUrl', function () { return ''; }, 'AngularConfig', '&3!>"&3#>$5w%'];
|
|
53
|
+
/**
|
|
54
|
+
* This object is available angular providers as DI token `REQUEST_CONTEXT`.
|
|
55
|
+
*/
|
|
56
|
+
class AngularRequestContext {
|
|
57
|
+
constructor(config) {
|
|
58
|
+
this.serverBaseUrl = '';
|
|
59
|
+
this.publicBaseUrl = '';
|
|
60
|
+
this.serverBaseUrl = config.serverBaseUrl;
|
|
61
|
+
this.publicBaseUrl = config.publicBaseUrl;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
AngularRequestContext.__type = ['serverBaseUrl', function () { return ''; }, 'publicBaseUrl', function () { return ''; }, () => AngularConfig, 'config', 'constructor', 'AngularRequestContext', '&3!>"&3#>$PP7%2&"0\'5w('];
|
|
65
|
+
let _ngApp = undefined;
|
|
66
|
+
class AngularListener {
|
|
67
|
+
constructor(requestContext) {
|
|
68
|
+
this.requestContext = requestContext;
|
|
69
|
+
}
|
|
70
|
+
async onRoute(event) {
|
|
71
|
+
if (event.route)
|
|
72
|
+
return; //already found
|
|
73
|
+
if (!_ngApp)
|
|
74
|
+
return;
|
|
75
|
+
const webRequest = (0, node_1.createWebRequestFromNodeRequest)(event.request);
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
const serverApp = await _ngApp.angularAppEngine.getAngularServerAppForRequest(webRequest);
|
|
78
|
+
const serverRouter = serverApp.router;
|
|
79
|
+
if (serverRouter) {
|
|
80
|
+
const matchedRoute = serverRouter.match(new URL(webRequest.url));
|
|
81
|
+
if (!matchedRoute) {
|
|
82
|
+
//not handled by angular app, so early exit
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
event.routeFound(new http_1.RouteConfig('angular', ['GET'], event.request.url || '', {
|
|
87
|
+
type: 'function',
|
|
88
|
+
fn: __assignType(async (req, res) => {
|
|
89
|
+
if (!_ngApp)
|
|
90
|
+
return;
|
|
91
|
+
const response = await _ngApp.handle(req, this.requestContext);
|
|
92
|
+
if (!response) {
|
|
93
|
+
throw new http_1.HttpNotFoundError();
|
|
94
|
+
}
|
|
95
|
+
await (0, node_1.writeResponseToNodeResponse)(response, res);
|
|
96
|
+
}, [() => http_1.HttpRequest, 'req', () => http_1.HttpResponse, 'res', '', 'PP7!2"P7#2$"/%']),
|
|
97
|
+
}), () => ({
|
|
98
|
+
arguments: [event.request, event.response],
|
|
99
|
+
parameters: {},
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
AngularListener.__type = [() => AngularRequestContext, 'requestContext', 'constructor', () => http_1.httpWorkflow.onRoute.event, 'event', 'onRoute', 'AngularListener', 'PP7!2":"0#Pi$2%"0&5w\''];
|
|
104
|
+
__decorate([
|
|
105
|
+
event_1.eventDispatcher.listen(http_1.httpWorkflow.onRoute, 102) //102 after 101=static listener, 100=default listener
|
|
106
|
+
,
|
|
107
|
+
__metadata("design:type", Function),
|
|
108
|
+
__metadata("design:paramtypes", [Object]),
|
|
109
|
+
__metadata("design:returntype", Promise)
|
|
110
|
+
], AngularListener.prototype, "onRoute", null);
|
|
111
|
+
class AngularStaticListener {
|
|
112
|
+
constructor() {
|
|
113
|
+
this.localPath = '';
|
|
114
|
+
this.path = '/'; //public path
|
|
115
|
+
}
|
|
116
|
+
onRoute(event) {
|
|
117
|
+
if (event.sent)
|
|
118
|
+
return;
|
|
119
|
+
if (event.route)
|
|
120
|
+
return;
|
|
121
|
+
if (!this.localPath)
|
|
122
|
+
return;
|
|
123
|
+
return (0, http_1.staticOnRoute)(event, this.path, this.localPath);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
AngularStaticListener.__type = ['localPath', function () { return ''; }, 'path', function () { return '/'; }, () => http_1.httpWorkflow.onRoute.event, 'event', 'onRoute', 'AngularStaticListener', '&3!>"&3#>$Pi%2&"0\'5w('];
|
|
127
|
+
__decorate([
|
|
128
|
+
event_1.eventDispatcher.listen(http_1.httpWorkflow.onRoute, 101) //after default route listener at 100
|
|
129
|
+
,
|
|
130
|
+
__metadata("design:type", Function),
|
|
131
|
+
__metadata("design:paramtypes", [Object]),
|
|
132
|
+
__metadata("design:returntype", void 0)
|
|
133
|
+
], AngularStaticListener.prototype, "onRoute", null);
|
|
134
|
+
/**
|
|
135
|
+
* This creates a request handler function for the Angular SSR server.
|
|
136
|
+
* It also starts ApplicationServer of Deepkit Framework to serve HTTP/RPC requests.
|
|
137
|
+
*
|
|
138
|
+
* ```typescript
|
|
139
|
+
* import { app } from './app';
|
|
140
|
+
* import { RequestHandler } from '@deepkit/angular-ssr';
|
|
141
|
+
*
|
|
142
|
+
* export const reqHandler = app.get(RequestHandler).create(import.meta.url);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
class RequestHandler {
|
|
146
|
+
constructor(logger, requestContext, http, server, staticListener) {
|
|
147
|
+
this.logger = logger;
|
|
148
|
+
this.requestContext = requestContext;
|
|
149
|
+
this.http = http;
|
|
150
|
+
this.server = server;
|
|
151
|
+
this.staticListener = staticListener;
|
|
152
|
+
this.started = false;
|
|
153
|
+
}
|
|
154
|
+
create(url, ngApp) {
|
|
155
|
+
var _a;
|
|
156
|
+
this.staticListener.localPath = (0, node_path_1.resolve)((0, node_path_1.dirname)((0, node_url_1.fileURLToPath)(url)), '../browser');
|
|
157
|
+
const global = ((_a = globalThis).deepkitAngular || (_a.deepkitAngular = {}));
|
|
158
|
+
const waitForClose = global.server ? global.server.close() : Promise.resolve();
|
|
159
|
+
_ngApp = ngApp;
|
|
160
|
+
// We only listen for process signals in the main module.
|
|
161
|
+
const listenOnSignals = (0, node_1.isMainModule)(url);
|
|
162
|
+
global.server = this.server;
|
|
163
|
+
const waitBootstrap = waitForClose.then(() => this.server.start({
|
|
164
|
+
listenOnSignals,
|
|
165
|
+
// startHttpServer: false,
|
|
166
|
+
})).then(() => {
|
|
167
|
+
let host = this.server.getHttpHost();
|
|
168
|
+
if (host?.startsWith('0.0.0.0')) {
|
|
169
|
+
host = 'localhost' + host.substr(7);
|
|
170
|
+
}
|
|
171
|
+
this.requestContext.serverBaseUrl = `http://${host}`;
|
|
172
|
+
if (!this.requestContext.serverBaseUrl) {
|
|
173
|
+
if ((0, node_1.isMainModule)(url)) {
|
|
174
|
+
this.requestContext.serverBaseUrl = 'http://localhost:8080';
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
//angular dev server
|
|
178
|
+
this.requestContext.serverBaseUrl = 'http://localhost:4200';
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
waitBootstrap.then(() => {
|
|
183
|
+
if (!global.started) {
|
|
184
|
+
this.logger.log('Angular SSR server bootstrap done, using REQUEST_CONTEXT', this.requestContext);
|
|
185
|
+
global.started = true;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
const handler = this.http.createMiddleware();
|
|
189
|
+
// every request in angular dev server is handled by this function
|
|
190
|
+
return (0, node_1.createNodeRequestHandler)(__assignType(async (req, res, next) => {
|
|
191
|
+
await waitBootstrap;
|
|
192
|
+
// if req wants to upgrade to websocket, we need to handle this here
|
|
193
|
+
if (req.headers.upgrade === 'websocket') {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
await handler(req, res, next);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
this.logger.log('createNodeRequestHandler error', error);
|
|
201
|
+
}
|
|
202
|
+
}, ['req', 'res', 'next', '', 'P"2!"2""2#"/$']));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.RequestHandler = RequestHandler;
|
|
206
|
+
RequestHandler.__type = ['started', function () { return false; }, () => logger_1.Logger, 'logger', () => AngularRequestContext, 'requestContext', () => http_1.HttpKernel, 'http', () => framework_1.ApplicationServer, 'server', () => AngularStaticListener, 'staticListener', 'constructor', 'url', () => node_1.AngularNodeAppEngine, 'ngApp', 'NodeRequestHandlerFunction', 'create', 'RequestHandler', ')3!<>"PP7#2$<P7%2&<P7\'2(<P7)2*<P7+2,<"0-P&2.P7/20"w1025w3'];
|
|
207
|
+
class AngularModule extends (0, app_1.createModuleClass)({
|
|
208
|
+
name: 'angular',
|
|
209
|
+
config: AngularConfig,
|
|
210
|
+
providers: [
|
|
211
|
+
RequestHandler,
|
|
212
|
+
AngularRequestContext,
|
|
213
|
+
AngularStaticListener,
|
|
214
|
+
],
|
|
215
|
+
exports: [
|
|
216
|
+
RequestHandler,
|
|
217
|
+
AngularRequestContext,
|
|
218
|
+
AngularStaticListener,
|
|
219
|
+
],
|
|
220
|
+
listeners: [
|
|
221
|
+
AngularListener,
|
|
222
|
+
AngularStaticListener,
|
|
223
|
+
],
|
|
224
|
+
}) {
|
|
225
|
+
}
|
|
226
|
+
exports.AngularModule = AngularModule;
|
|
227
|
+
AngularModule.__type = [() => (0, app_1.createModuleClass)({ name: "angular", config: AngularConfig, providers: [RequestHandler, AngularRequestContext, AngularStaticListener], exports: [RequestHandler, AngularRequestContext, AngularStaticListener], listeners: [AngularListener, AngularStaticListener] }), 'AngularModule', 'P7!5w"'];
|
|
228
|
+
//# sourceMappingURL=angular.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angular.js","sourceRoot":"","sources":["../../../src/angular.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;GAQG;AAEH,4CAO2B;AAC3B,wCAQuB;AACvB,0CAAiD;AACjD,sCAAiD;AACjD,kDAAuD;AACvD,4CAAyC;AACzC,yCAA6C;AAC7C,uCAAyC;AAEzC,MAAM,aAAa;IAAnB;QACI;;;;;WAKG;QACH,kBAAa,GAAW,EAAE,CAAC;QAE3B;;;;;WAKG;QACH,kBAAa,GAAW,EAAE,CAAC;KAC9B;;8DAT2B,EAAE,2CAQF,EAAE;AAG9B;;GAEG;AACH,MAAM,qBAAqB;IAIvB,YAAY,MAAqB;QAHjC,kBAAa,GAAW,EAAE,CAAC;QAC3B,kBAAa,GAAW,EAAE,CAAC;QAGvB,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa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