@schematics/angular 20.0.0-next.1 → 20.0.0-next.2
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/app-shell/index.js +11 -118
- package/app-shell/schema.d.ts +0 -5
- package/app-shell/schema.json +0 -5
- package/application/files/module-files/src/app/app.module.ts.template +3 -3
- package/application/files/module-files/src/app/{app.component.spec.ts.template → app.spec.ts.template} +6 -6
- package/application/files/module-files/src/app/{app.component.ts.template → app.ts.template} +3 -3
- package/application/files/module-files/src/main.ts.template +2 -2
- package/application/files/standalone-files/src/app/{app.component.spec.ts.template → app.spec.ts.template} +6 -6
- package/application/files/standalone-files/src/app/{app.component.ts.template → app.ts.template} +3 -3
- package/application/files/standalone-files/src/main.ts.template +2 -2
- package/application/index.js +0 -1
- package/application/schema.d.ts +0 -5
- package/application/schema.json +0 -4
- package/component/index.js +2 -0
- package/component/schema.json +1 -2
- package/directive/files/__name@dasherize__.__type@dasherize__.spec.ts.template +8 -0
- package/directive/files/{__name@dasherize@if-flat__/__name@dasherize__.directive.ts.template → __name@dasherize__.__type@dasherize__.ts.template} +1 -1
- package/directive/index.js +4 -10
- package/directive/schema.d.ts +5 -0
- package/directive/schema.json +4 -0
- package/library/files/src/__entryFile__.ts.template +1 -2
- package/library/index.js +0 -6
- package/migrations/migration-collection.json +10 -0
- package/migrations/replace-provide-server-rendering-import/migration.d.ts +9 -0
- package/migrations/replace-provide-server-rendering-import/migration.js +133 -0
- package/migrations/replace-provide-server-routing/migration.d.ts +9 -0
- package/migrations/replace-provide-server-routing/migration.js +122 -0
- package/module/files/__name@dasherize@if-flat__/__name@dasherize__-routing.module.ts.template +2 -2
- package/module/files/__name@dasherize@if-flat__/__name@dasherize__.module.ts.template +1 -1
- package/ng-new/index.js +0 -1
- package/ng-new/schema.d.ts +0 -5
- package/ng-new/schema.json +0 -4
- package/package.json +3 -3
- package/server/files/application-builder/ngmodule-src/app/app.module.server.ts.template +7 -8
- package/server/files/application-builder/standalone-src/app/app.config.server.ts.template +4 -6
- package/server/files/application-builder/standalone-src/main.server.ts.template +2 -2
- package/server/files/server-builder/ngmodule-src/app/app.module.server.ts.template +2 -2
- package/server/files/server-builder/standalone-src/app/app.config.server.ts.template +1 -1
- package/server/files/server-builder/standalone-src/main.server.ts.template +2 -2
- package/server/index.js +5 -11
- package/server/schema.d.ts +0 -5
- package/server/schema.json +0 -4
- package/service/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template +16 -0
- package/service/files/__name@dasherize@if-flat__/{__name@dasherize__.service.ts.template → __name@dasherize__.__type@dasherize__.ts.template} +1 -1
- package/service/index.js +2 -0
- package/service/schema.d.ts +5 -0
- package/service/schema.json +4 -0
- package/ssr/index.d.ts +1 -3
- package/ssr/index.js +11 -96
- package/ssr/schema.d.ts +0 -5
- package/ssr/schema.json +0 -4
- package/utility/find-module.js +1 -1
- package/utility/generate-from-files.d.ts +1 -0
- package/utility/generate-from-files.js +10 -0
- package/utility/latest-versions.js +3 -3
- package/utility/project-targets.d.ts +2 -0
- package/utility/project-targets.js +7 -0
- package/web-worker/index.js +1 -1
- package/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.spec.ts.template +0 -8
- package/service/files/__name@dasherize@if-flat__/__name@dasherize__.service.spec.ts.template +0 -16
- package/ssr/files/application-builder-common-engine/server.ts.template +0 -67
- /package/application/files/common-files/src/app/{app.component.ng.html.template → app.ng.html.template} +0 -0
package/ssr/index.js
CHANGED
|
@@ -6,42 +6,8 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.dev/license
|
|
8
8
|
*/
|
|
9
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
-
}
|
|
15
|
-
Object.defineProperty(o, k2, desc);
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
-
var ownKeys = function(o) {
|
|
27
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
-
var ar = [];
|
|
29
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
-
return ar;
|
|
31
|
-
};
|
|
32
|
-
return ownKeys(o);
|
|
33
|
-
};
|
|
34
|
-
return function (mod) {
|
|
35
|
-
if (mod && mod.__esModule) return mod;
|
|
36
|
-
var result = {};
|
|
37
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
-
__setModuleDefault(result, mod);
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
})();
|
|
42
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
10
|
exports.default = default_1;
|
|
44
|
-
exports.setPrompterForTestOnly = setPrompterForTestOnly;
|
|
45
11
|
const core_1 = require("@angular-devkit/core");
|
|
46
12
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
47
13
|
const node_path_1 = require("node:path");
|
|
@@ -52,8 +18,6 @@ const ng_ast_utils_1 = require("../utility/ng-ast-utils");
|
|
|
52
18
|
const project_targets_1 = require("../utility/project-targets");
|
|
53
19
|
const util_1 = require("../utility/standalone/util");
|
|
54
20
|
const workspace_1 = require("../utility/workspace");
|
|
55
|
-
const workspace_models_1 = require("../utility/workspace-models");
|
|
56
|
-
const tty_1 = require("./tty");
|
|
57
21
|
const SERVE_SSR_TARGET_NAME = 'serve-ssr';
|
|
58
22
|
const PRERENDER_TARGET_NAME = 'prerender';
|
|
59
23
|
const DEFAULT_BROWSER_DIR = 'browser';
|
|
@@ -174,8 +138,7 @@ function updateApplicationBuilderWorkspaceConfigRule(projectSourceRoot, options,
|
|
|
174
138
|
buildTarget.options = {
|
|
175
139
|
...buildTarget.options,
|
|
176
140
|
outputPath,
|
|
177
|
-
outputMode:
|
|
178
|
-
prerender: options.serverRouting ? undefined : true,
|
|
141
|
+
outputMode: 'server',
|
|
179
142
|
ssr: {
|
|
180
143
|
entry: (0, core_1.join)((0, core_1.normalize)(projectSourceRoot), 'server.ts'),
|
|
181
144
|
},
|
|
@@ -285,12 +248,11 @@ function addServerFile(projectSourceRoot, options, isStandalone) {
|
|
|
285
248
|
if (!project) {
|
|
286
249
|
throw new schematics_1.SchematicsException(`Invalid project name (${projectName})`);
|
|
287
250
|
}
|
|
288
|
-
const
|
|
289
|
-
const browserDistDirectory =
|
|
251
|
+
const usingApplicationBuilder = (0, project_targets_1.isUsingApplicationBuilder)(project);
|
|
252
|
+
const browserDistDirectory = usingApplicationBuilder
|
|
290
253
|
? (await getApplicationBuilderOutputPaths(host, projectName)).browser
|
|
291
254
|
: await getLegacyOutputPaths(host, projectName, 'build');
|
|
292
|
-
|
|
293
|
-
return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(`./files/${isUsingApplicationBuilder ? applicationBuilderFiles : 'server-builder'}`), [
|
|
255
|
+
return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(`./files/${usingApplicationBuilder ? 'application-builder' : 'server-builder'}`), [
|
|
294
256
|
(0, schematics_1.applyTemplates)({
|
|
295
257
|
...core_1.strings,
|
|
296
258
|
...options,
|
|
@@ -301,25 +263,23 @@ function addServerFile(projectSourceRoot, options, isStandalone) {
|
|
|
301
263
|
]));
|
|
302
264
|
};
|
|
303
265
|
}
|
|
304
|
-
function default_1(
|
|
266
|
+
function default_1(options) {
|
|
305
267
|
return async (host, context) => {
|
|
306
|
-
const browserEntryPoint = await (0, util_1.getMainFilePath)(host,
|
|
268
|
+
const browserEntryPoint = await (0, util_1.getMainFilePath)(host, options.project);
|
|
307
269
|
const isStandalone = (0, ng_ast_utils_1.isStandaloneApp)(host, browserEntryPoint);
|
|
308
270
|
const workspace = await (0, workspace_1.getWorkspace)(host);
|
|
309
|
-
const clientProject = workspace.projects.get(
|
|
271
|
+
const clientProject = workspace.projects.get(options.project);
|
|
310
272
|
if (!clientProject) {
|
|
311
273
|
throw (0, project_targets_1.targetBuildNotFoundError)();
|
|
312
274
|
}
|
|
313
|
-
const
|
|
314
|
-
const serverRouting = await isServerRoutingEnabled(isUsingApplicationBuilder, inputOptions);
|
|
315
|
-
const options = { ...inputOptions, serverRouting };
|
|
275
|
+
const usingApplicationBuilder = (0, project_targets_1.isUsingApplicationBuilder)(clientProject);
|
|
316
276
|
const sourceRoot = clientProject.sourceRoot ?? node_path_1.posix.join(clientProject.root, 'src');
|
|
317
277
|
return (0, schematics_1.chain)([
|
|
318
278
|
(0, schematics_1.schematic)('server', {
|
|
319
279
|
...options,
|
|
320
280
|
skipInstall: true,
|
|
321
281
|
}),
|
|
322
|
-
...(
|
|
282
|
+
...(usingApplicationBuilder
|
|
323
283
|
? [
|
|
324
284
|
updateApplicationBuilderWorkspaceConfigRule(sourceRoot, options, context),
|
|
325
285
|
updateApplicationBuilderTsConfigRule(options),
|
|
@@ -329,53 +289,8 @@ function default_1(inputOptions) {
|
|
|
329
289
|
updateWebpackBuilderWorkspaceConfigRule(sourceRoot, options),
|
|
330
290
|
]),
|
|
331
291
|
addServerFile(sourceRoot, options, isStandalone),
|
|
332
|
-
addScriptsRule(options,
|
|
333
|
-
addDependencies(options,
|
|
292
|
+
addScriptsRule(options, usingApplicationBuilder),
|
|
293
|
+
addDependencies(options, usingApplicationBuilder),
|
|
334
294
|
]);
|
|
335
295
|
};
|
|
336
296
|
}
|
|
337
|
-
function usingApplicationBuilder(project) {
|
|
338
|
-
const buildBuilder = project.targets.get('build')?.builder;
|
|
339
|
-
const isUsingApplicationBuilder = buildBuilder === workspace_models_1.Builders.Application || buildBuilder === workspace_models_1.Builders.BuildApplication;
|
|
340
|
-
return isUsingApplicationBuilder;
|
|
341
|
-
}
|
|
342
|
-
const defaultPrompter = async (message, defaultValue) => {
|
|
343
|
-
const { confirm } = await Promise.resolve().then(() => __importStar(require('@inquirer/prompts')));
|
|
344
|
-
return await confirm({
|
|
345
|
-
message,
|
|
346
|
-
default: defaultValue,
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
// Allow the prompt functionality to be overridden to facilitate testing.
|
|
350
|
-
let prompt = defaultPrompter;
|
|
351
|
-
function setPrompterForTestOnly(prompter) {
|
|
352
|
-
prompt = prompter ?? defaultPrompter;
|
|
353
|
-
}
|
|
354
|
-
/** Returns whether or not server routing is enabled, potentially prompting the user if necessary. */
|
|
355
|
-
async function isServerRoutingEnabled(isUsingApplicationBuilder, options) {
|
|
356
|
-
if (!isUsingApplicationBuilder) {
|
|
357
|
-
if (options.serverRouting) {
|
|
358
|
-
throw new schematics_1.SchematicsException('Server routing APIs can only be added to a project using `application` builder.');
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
// Use explicit option if provided.
|
|
365
|
-
if (options.serverRouting !== undefined) {
|
|
366
|
-
return options.serverRouting;
|
|
367
|
-
}
|
|
368
|
-
const serverRoutingDefault = false;
|
|
369
|
-
// Use the default if not in an interactive terminal.
|
|
370
|
-
if (!(0, tty_1.isTTY)()) {
|
|
371
|
-
return serverRoutingDefault;
|
|
372
|
-
}
|
|
373
|
-
// `inquirer` requires `async_hooks` which isn't supported by webcontainers, therefore we can't prompt in that context.
|
|
374
|
-
// See: https://github.com/SBoudrias/Inquirer.js/issues/1426
|
|
375
|
-
if (process.versions.webcontainer) {
|
|
376
|
-
return serverRoutingDefault;
|
|
377
|
-
}
|
|
378
|
-
// Prompt the user if in an interactive terminal and no option was provided.
|
|
379
|
-
return await prompt('Would you like to use the Server Routing and App Engine APIs (Developer Preview) for this server application?',
|
|
380
|
-
/* defaultValue */ serverRoutingDefault);
|
|
381
|
-
}
|
package/ssr/schema.d.ts
CHANGED
|
@@ -10,11 +10,6 @@ export type Schema = {
|
|
|
10
10
|
* The name of the project you want to enable SSR for.
|
|
11
11
|
*/
|
|
12
12
|
project: string;
|
|
13
|
-
/**
|
|
14
|
-
* Configure the server application to use the Angular Server Routing API and App Engine
|
|
15
|
-
* APIs (currently in Developer Preview).
|
|
16
|
-
*/
|
|
17
|
-
serverRouting?: boolean;
|
|
18
13
|
/**
|
|
19
14
|
* Skip the automatic installation of packages. You will need to manually install the
|
|
20
15
|
* dependencies later.
|
package/ssr/schema.json
CHANGED
|
@@ -16,10 +16,6 @@
|
|
|
16
16
|
"description": "Skip the automatic installation of packages. You will need to manually install the dependencies later.",
|
|
17
17
|
"type": "boolean",
|
|
18
18
|
"default": false
|
|
19
|
-
},
|
|
20
|
-
"serverRouting": {
|
|
21
|
-
"description": "Configure the server application to use the Angular Server Routing API and App Engine APIs (currently in Developer Preview).",
|
|
22
|
-
"type": "boolean"
|
|
23
19
|
}
|
|
24
20
|
},
|
|
25
21
|
"required": ["project"],
|
package/utility/find-module.js
CHANGED
|
@@ -42,7 +42,7 @@ function findModuleFromOptions(host, options) {
|
|
|
42
42
|
for (const c of candidatesDirs) {
|
|
43
43
|
const candidateFiles = ['', `${moduleBaseName}.ts`, `${moduleBaseName}${moduleExt}`].map((x) => (0, core_1.join)(c, x));
|
|
44
44
|
for (const sc of candidateFiles) {
|
|
45
|
-
if (host.exists(sc)) {
|
|
45
|
+
if (host.exists(sc) && host.readText(sc).includes('@NgModule')) {
|
|
46
46
|
return (0, core_1.normalize)(sc);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -14,5 +14,6 @@ export interface GenerateFromFilesOptions {
|
|
|
14
14
|
project: string;
|
|
15
15
|
skipTests?: boolean;
|
|
16
16
|
templateFilesDirectory?: string;
|
|
17
|
+
type?: string;
|
|
17
18
|
}
|
|
18
19
|
export declare function generateFromFiles(options: GenerateFromFilesOptions, extraTemplateValues?: Record<string, string | ((v: string) => string)>): Rule;
|
|
@@ -29,6 +29,16 @@ function generateFromFiles(options, extraTemplateValues = {}) {
|
|
|
29
29
|
...options,
|
|
30
30
|
...extraTemplateValues,
|
|
31
31
|
}),
|
|
32
|
+
!options.type
|
|
33
|
+
? (0, schematics_1.forEach)(((file) => {
|
|
34
|
+
return file.path.includes('..')
|
|
35
|
+
? {
|
|
36
|
+
content: file.content,
|
|
37
|
+
path: file.path.replace('..', '.'),
|
|
38
|
+
}
|
|
39
|
+
: file;
|
|
40
|
+
}))
|
|
41
|
+
: (0, schematics_1.noop)(),
|
|
32
42
|
(0, schematics_1.move)(parsedPath.path + (options.flat ? '' : '/' + schematics_1.strings.dasherize(options.name))),
|
|
33
43
|
]);
|
|
34
44
|
return (0, schematics_1.chain)([(0, schematics_1.mergeWith)(templateSource)]);
|
|
@@ -16,7 +16,7 @@ exports.latestVersions = {
|
|
|
16
16
|
// As Angular CLI works with same minor versions of Angular Framework, a tilde match for the current
|
|
17
17
|
Angular: '^20.0.0-next.0',
|
|
18
18
|
NgPackagr: '^20.0.0-next.0',
|
|
19
|
-
DevkitBuildAngular: '^20.0.0-next.
|
|
20
|
-
AngularBuild: '^20.0.0-next.
|
|
21
|
-
AngularSSR: '^20.0.0-next.
|
|
19
|
+
DevkitBuildAngular: '^20.0.0-next.2',
|
|
20
|
+
AngularBuild: '^20.0.0-next.2',
|
|
21
|
+
AngularSSR: '^20.0.0-next.2',
|
|
22
22
|
};
|
|
@@ -6,4 +6,6 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
8
|
import { SchematicsException } from '@angular-devkit/schematics';
|
|
9
|
+
import { ProjectDefinition } from './workspace';
|
|
9
10
|
export declare function targetBuildNotFoundError(): SchematicsException;
|
|
11
|
+
export declare function isUsingApplicationBuilder(project: ProjectDefinition): boolean;
|
|
@@ -8,7 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.targetBuildNotFoundError = targetBuildNotFoundError;
|
|
11
|
+
exports.isUsingApplicationBuilder = isUsingApplicationBuilder;
|
|
11
12
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
13
|
+
const workspace_models_1 = require("./workspace-models");
|
|
12
14
|
function targetBuildNotFoundError() {
|
|
13
15
|
return new schematics_1.SchematicsException(`Project target "build" not found.`);
|
|
14
16
|
}
|
|
17
|
+
function isUsingApplicationBuilder(project) {
|
|
18
|
+
const buildBuilder = project.targets.get('build')?.builder;
|
|
19
|
+
const isUsingApplicationBuilder = buildBuilder === workspace_models_1.Builders.Application || buildBuilder === workspace_models_1.Builders.BuildApplication;
|
|
20
|
+
return isUsingApplicationBuilder;
|
|
21
|
+
}
|
package/web-worker/index.js
CHANGED
|
@@ -24,7 +24,7 @@ function addSnippet(options) {
|
|
|
24
24
|
.getDir(options.path)
|
|
25
25
|
.subfiles // Find all files that start with the same name, are ts files,
|
|
26
26
|
// and aren't spec or module files.
|
|
27
|
-
.filter((f) => fileRegExp.test(f) && !/(module|spec)\.ts$/.test(f))
|
|
27
|
+
.filter((f) => fileRegExp.test(f) && !/(module|spec|config|routes)\.ts$/.test(f))
|
|
28
28
|
// Sort alphabetically for consistency.
|
|
29
29
|
.sort();
|
|
30
30
|
if (siblingModules.length === 0) {
|
package/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.spec.ts.template
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { <%= classify(name) %>Directive } from './<%= dasherize(name) %>.directive';
|
|
2
|
-
|
|
3
|
-
describe('<%= classify(name) %>Directive', () => {
|
|
4
|
-
it('should create an instance', () => {
|
|
5
|
-
const directive = new <%= classify(name) %>Directive();
|
|
6
|
-
expect(directive).toBeTruthy();
|
|
7
|
-
});
|
|
8
|
-
});
|
package/service/files/__name@dasherize@if-flat__/__name@dasherize__.service.spec.ts.template
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
|
|
3
|
-
import { <%= classify(name) %>Service } from './<%= dasherize(name) %>.service';
|
|
4
|
-
|
|
5
|
-
describe('<%= classify(name) %>Service', () => {
|
|
6
|
-
let service: <%= classify(name) %>Service;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
TestBed.configureTestingModule({});
|
|
10
|
-
service = TestBed.inject(<%= classify(name) %>Service);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should be created', () => {
|
|
14
|
-
expect(service).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { APP_BASE_HREF } from '@angular/common';
|
|
2
|
-
import { CommonEngine, isMainModule } from '@angular/ssr/node';
|
|
3
|
-
import express from 'express';
|
|
4
|
-
import { dirname, join, resolve } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import <% if (isStandalone) { %>bootstrap<% } else { %>AppServerModule<% } %> from './main.server';
|
|
7
|
-
|
|
8
|
-
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
const browserDistFolder = resolve(serverDistFolder, '../<%= browserDistDirectory %>');
|
|
10
|
-
const indexHtml = join(serverDistFolder, 'index.server.html');
|
|
11
|
-
|
|
12
|
-
const app = express();
|
|
13
|
-
const commonEngine = new CommonEngine();
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Example Express Rest API endpoints can be defined here.
|
|
17
|
-
* Uncomment and define endpoints as necessary.
|
|
18
|
-
*
|
|
19
|
-
* Example:
|
|
20
|
-
* ```ts
|
|
21
|
-
* app.get('/api/**', (req, res) => {
|
|
22
|
-
* // Handle API request
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Serve static files from /<%= browserDistDirectory %>
|
|
29
|
-
*/
|
|
30
|
-
app.get(
|
|
31
|
-
'**',
|
|
32
|
-
express.static(browserDistFolder, {
|
|
33
|
-
maxAge: '1y',
|
|
34
|
-
index: 'index.html'
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Handle all other requests by rendering the Angular application.
|
|
40
|
-
*/
|
|
41
|
-
app.get('**', (req, res, next) => {
|
|
42
|
-
const { protocol, originalUrl, baseUrl, headers } = req;
|
|
43
|
-
|
|
44
|
-
commonEngine
|
|
45
|
-
.render({
|
|
46
|
-
<% if (isStandalone) { %>bootstrap<% } else { %>bootstrap: AppServerModule<% } %>,
|
|
47
|
-
documentFilePath: indexHtml,
|
|
48
|
-
url: `${protocol}://${headers.host}${originalUrl}`,
|
|
49
|
-
publicPath: browserDistFolder,
|
|
50
|
-
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
|
|
51
|
-
})
|
|
52
|
-
.then((html) => res.send(html))
|
|
53
|
-
.catch((err) => next(err));
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Start the server if this module is the main entry point.
|
|
58
|
-
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
|
|
59
|
-
*/
|
|
60
|
-
if (isMainModule(import.meta.url)) {
|
|
61
|
-
const port = process.env['PORT'] || 4000;
|
|
62
|
-
app.listen(port, () => {
|
|
63
|
-
console.log(`Node Express server listening on http://localhost:${port}`);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default app;
|
|
File without changes
|