Skip to content

Commit e22339c

Browse files
committed
SSR workaround
1 parent b53e20c commit e22339c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/server.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { APP_BASE_HREF } from '@angular/common';
2-
import { CommonEngine, isMainModule } from '@angular/ssr/node';
2+
import { CommonEngine, createNodeRequestHandler, isMainModule } from '@angular/ssr/node';
33
import express from 'express';
44
import { dirname, join, resolve } from 'node:path';
55
import { fileURLToPath } from 'node:url';
@@ -9,7 +9,7 @@ const serverDistFolder = dirname(fileURLToPath(import.meta.url));
99
const browserDistFolder = resolve(serverDistFolder, '../browser');
1010
const indexHtml = join(serverDistFolder, 'index.server.html');
1111

12-
const app = express();
12+
const server = express();
1313
const commonEngine = new CommonEngine();
1414

1515
/**
@@ -27,7 +27,7 @@ const commonEngine = new CommonEngine();
2727
/**
2828
* Serve static files from /browser
2929
*/
30-
app.get(
30+
server.get(
3131
'**',
3232
express.static(browserDistFolder, {
3333
maxAge: '1y',
@@ -38,7 +38,7 @@ app.get(
3838
/**
3939
* Handle all other requests by rendering the Angular application.
4040
*/
41-
app.get('**', (req, res, next) => {
41+
server.get('**', (req, res, next) => {
4242
const { protocol, originalUrl, baseUrl, headers } = req;
4343

4444
commonEngine
@@ -59,7 +59,21 @@ app.get('**', (req, res, next) => {
5959
*/
6060
if (isMainModule(import.meta.url)) {
6161
const port = process.env['PORT'] || 4000;
62-
app.listen(port, () => {
62+
server.listen(port, () => {
6363
console.log(`Node Express server listening on http://localhost:${port}`);
6464
});
6565
}
66+
67+
/** workaround **/
68+
// using the suggestion from the documentation: https://angular.dev/guide/hybrid-rendering#configuring-a-nodejs-server
69+
70+
// export const reqHandler = createNodeRequestHandler(app);
71+
72+
// doesn't work, this would be on the firebase-tools side at:
73+
// - see https://github.com/firebase/firebase-tools/pull/8145
74+
// - see https://github.com/firebase/firebase-tools/pull/8145/commits/6bfdff095902c9ec469d6fe8c82223987e43e213
75+
76+
/**
77+
* The request handler used by the Angular CLI (dev-server and during build).
78+
*/
79+
export const app = () => createNodeRequestHandler(server);

0 commit comments

Comments
 (0)