Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@types/babel__core": "7.20.5",
"@types/babel__generator": "^7.6.8",
"@types/browser-sync": "^2.27.0",
"@types/express": "^4.16.0",
"@types/express": "~5.0.1",
"@types/http-proxy": "^1.17.4",
"@types/ini": "^4.0.0",
"@types/jasmine": "~5.1.0",
Expand Down Expand Up @@ -106,7 +106,7 @@
"eslint-config-prettier": "10.1.1",
"eslint-plugin-header": "3.1.1",
"eslint-plugin-import": "2.31.0",
"express": "4.21.2",
"express": "5.1.0",
"fast-glob": "3.3.3",
"globals": "16.0.0",
"http-proxy": "^1.18.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ describe('Serve SSR Builder', () => {
server.set('view engine', 'html');
server.set('views', distFolder);

server.get('*.*', express.static(distFolder, {
maxAge: '1y'
server.use(express.static(distFolder, {
maxAge: '1y',
index: false,
}));

server.get('*', (req, res, next) => {
server.use((req, res, next) => {
commonEngine
.render({
bootstrap: AppServerModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ describe('Serve SSR Builder', () => {
server.set('view engine', 'html');
server.set('views', distFolder);

server.get('*.*', express.static(distFolder, {
maxAge: '1y'
server.use(express.static(distFolder, {
maxAge: '1y',
index: false,
}));

server.get('*', (req, res, next) => {
server.use((req, res, next) => {
commonEngine
.render({
bootstrap: AppServerModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ describe('Serve SSR Builder', () => {
server.set('view engine', 'html');
server.set('views', distFolder);

server.get('*.*', express.static(distFolder, {
maxAge: '1y'
server.use(express.static(distFolder, {
maxAge: '1y',
index: false,
}));

server.get('*', (req, res, next) => {
server.use((req, res, next) => {
commonEngine
.render({
bootstrap: AppServerModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ function* updateBuildTarget(

yield externalSchematic('@schematics/angular', 'ssr', {
project: projectName,
skipInstall: true,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const angularApp = new AngularNodeAppEngine();
*
* Example:
* ```ts
* app.get('/api/**', (req, res) => {
* app.get('/api/{*splat}', (req, res) => {
* // Handle API request
* });
* ```
Expand All @@ -38,7 +38,7 @@ app.use(
/**
* Handle all other requests by rendering the Angular application.
*/
app.use('/**', (req, res, next) => {
app.use((req, res, next) => {
angularApp
.handle(req)
.then((response) =>
Expand All @@ -53,7 +53,11 @@ app.use('/**', (req, res, next) => {
*/
if (isMainModule(import.meta.url)) {
const port = process.env['PORT'] || 4000;
app.listen(port, () => {
app.listen(port, (error) => {
if (error) {
throw error;
}

console.log(`Node Express server listening on http://localhost:${port}`);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ export function app(): express.Express {
server.set('views', distFolder);

// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// server.get('/api/{*splat}', (req, res) => { });
// Serve static files from /browser
server.get('*.*', express.static(distFolder, {
maxAge: '1y'
server.use(express.static(distFolder, {
maxAge: '1y',
index: false,
}));

// All regular routes use the Angular engine
server.get('*', (req, res, next) => {
server.use((req, res, next) => {
const { protocol, originalUrl, baseUrl, headers } = req;

commonEngine
Expand All @@ -51,7 +52,11 @@ function run(): void {

// Start up the Node server
const server = app();
server.listen(port, () => {
server.listen(port, (error) => {
if (error) {
throw error;
}

console.log(`Node Express server listening on http://localhost:${port}`);
});
}
Expand Down
3 changes: 3 additions & 0 deletions packages/schematics/angular/ssr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { posix } from 'node:path';
import { Schema as ServerOptions } from '../server/schema';
import {
DependencyType,
ExistingBehavior,
InstallBehavior,
addDependency,
readWorkspace,
Expand Down Expand Up @@ -299,10 +300,12 @@ function addDependencies({ skipInstall }: SSROptions, isUsingApplicationBuilder:
addDependency('express', latestVersions['express'], {
type: DependencyType.Default,
install,
existing: ExistingBehavior.Replace,
}),
addDependency('@types/express', latestVersions['@types/express'], {
type: DependencyType.Dev,
install,
existing: ExistingBehavior.Replace,
}),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"comment": "This file is needed so that dependencies are synced by Renovate.",
"private": true,
"dependencies": {
"@types/express": "^4.17.17",
"@types/express": "^5.0.1",
"@types/jasmine": "~5.1.0",
"@types/node": "^20.17.19",
"browser-sync": "^3.0.0",
"express": "^4.18.2",
"express": "^5.1.0",
"jasmine-core": "~5.6.0",
"jasmine-spec-reporter": "~7.0.0",
"karma-chrome-launcher": "~3.2.0",
Expand Down
Loading
Loading