Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 0ceaaba

Browse files
vikermanCaerusKaru
authored andcommitted
fix(express-engine): set APP_BASE_HREF to req.baseUrl (#1252)
This avoids Angular route match failures when the Express engine is mounted on a different URL (this happens e.g. with Firebase and other serverless setups).
1 parent c0eb354 commit 0ceaaba

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

integration/express-engine-ivy/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as express from 'express';
55
import { join } from 'path';
66

77
import { AppServerModule } from './src/main.server';
8+
import { APP_BASE_HREF } from '@angular/common';
89

910
// The Express app is exported so that it can be used by serverless Functions.
1011
export function app() {
@@ -28,7 +29,7 @@ export function app() {
2829

2930
// All regular routes use the Universal engine
3031
server.get('*', (req, res) => {
31-
res.render('index', { req });
32+
res.render('index', { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
3233
});
3334

3435
return server;

integration/express-engine-ve/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as express from 'express';
55
import { join } from 'path';
66

77
import { AppServerModuleNgFactory } from './src/main.server';
8+
import { APP_BASE_HREF } from '@angular/common';
89

910
// The Express app is exported so that it can be used by serverless Functions.
1011
export function app() {
@@ -28,7 +29,7 @@ export function app() {
2829

2930
// All regular routes use the Universal engine
3031
server.get('*', (req, res) => {
31-
res.render('index', { req });
32+
res.render('index', { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
3233
});
3334

3435
return server;

modules/express-engine/schematics/install/files/__serverFileName@stripTsExtension__.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as express from 'express';
55
import { join } from 'path';
66

77
import { AppServerModule } from './src/<%= stripTsExtension(main) %>';
8+
import { APP_BASE_HREF } from '@angular/common';
89

910
// The Express app is exported so that it can be used by serverless Functions.
1011
export function app() {
@@ -28,7 +29,7 @@ export function app() {
2829

2930
// All regular routes use the Universal engine
3031
server.get('*', (req, res) => {
31-
res.render('index', { req });
32+
res.render('index', { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
3233
});
3334

3435
return server;

0 commit comments

Comments
 (0)