Skip to content

Commit c0dcbd3

Browse files
fix: support default and reqHandler exports in Angular (#8145)
* fix: support `default` and `reqHandler` exports in Angular Updated the export structure to ensure both `default` and `reqHandler` exports function when using Angular. * changelog * bump supported angular version * changelog for version bump --------- Co-authored-by: Leonardo Ortiz <[email protected]>
1 parent 4670380 commit c0dcbd3

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
- Added code generation of React hooks for Data Connect
22
- Genkit init improvements around gcloud login and flow input values.
33
- Fixes symbol generation when uploading Unity 6 symbols to Crashlytics.
4+
- Fixed SSR issues in Angular 19 by adding support for default and reqHandler exports. (#8145)
5+
- Added Angular 19 as supported version. (#8145)

src/frameworks/angular/index.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const docsUrl = "https://firebase.google.com/docs/hosting/frameworks/angu
3636

3737
const DEFAULT_BUILD_SCRIPT = ["ng build"];
3838

39-
export const supportedRange = "16 - 18";
39+
export const supportedRange = "16 - 19";
4040

4141
export async function discover(dir: string): Promise<Discovery | undefined> {
4242
if (!(await pathExists(join(dir, "package.json")))) return;
@@ -243,19 +243,24 @@ exports.handle = function(req,res) {
243243
};\n`;
244244
} else if (serverOutputPath) {
245245
bootstrapScript = `
246-
const app = new Promise((resolve) => {
246+
const app = new Promise((resolve, reject) => {
247247
setTimeout(() => {
248248
const port = process.env.PORT;
249249
const socket = 'express.sock';
250250
process.env.PORT = socket;
251-
251+
252252
${
253253
serverEntry?.endsWith(".mjs")
254254
? `import(\`./${serverOutputPath}/${serverEntry}\`)`
255255
: `Promise.resolve(require('./${serverOutputPath}/${serverEntry}'))`
256-
}.then(({ app }) => {
257-
process.env.PORT = port;
258-
resolve(app());
256+
}.then(({ default: defHandler, reqHandler, app }) => {
257+
const handler = app?.() ?? reqHandler ?? defHandler;
258+
if (!handler) {
259+
reject(\`The file at "./${serverOutputPath}/${serverEntry}" did not export a valid request handler. Expected exports: 'app', 'default', or 'reqHandler'.\`);
260+
} else {
261+
process.env.PORT = port;
262+
resolve(handler);
263+
}
259264
});
260265
}, 0);
261266
});

0 commit comments

Comments
 (0)