Skip to content

Commit

Permalink
fix: support default and reqHandler exports in Angular (#8145)
Browse files Browse the repository at this point in the history
* 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 <leo@monogram.io>
  • Loading branch information
alan-agius4 and leoortizz authored Feb 8, 2025
1 parent 4670380 commit c0dcbd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Added code generation of React hooks for Data Connect
- Genkit init improvements around gcloud login and flow input values.
- Fixes symbol generation when uploading Unity 6 symbols to Crashlytics.
- Fixed SSR issues in Angular 19 by adding support for default and reqHandler exports. (#8145)
- Added Angular 19 as supported version. (#8145)
17 changes: 11 additions & 6 deletions src/frameworks/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const docsUrl = "https://firebase.google.com/docs/hosting/frameworks/angu

const DEFAULT_BUILD_SCRIPT = ["ng build"];

export const supportedRange = "16 - 18";
export const supportedRange = "16 - 19";

export async function discover(dir: string): Promise<Discovery | undefined> {
if (!(await pathExists(join(dir, "package.json")))) return;
Expand Down Expand Up @@ -243,19 +243,24 @@ exports.handle = function(req,res) {
};\n`;
} else if (serverOutputPath) {
bootstrapScript = `
const app = new Promise((resolve) => {
const app = new Promise((resolve, reject) => {
setTimeout(() => {
const port = process.env.PORT;
const socket = 'express.sock';
process.env.PORT = socket;
${
serverEntry?.endsWith(".mjs")
? `import(\`./${serverOutputPath}/${serverEntry}\`)`
: `Promise.resolve(require('./${serverOutputPath}/${serverEntry}'))`
}.then(({ app }) => {
process.env.PORT = port;
resolve(app());
}.then(({ default: defHandler, reqHandler, app }) => {
const handler = app?.() ?? reqHandler ?? defHandler;
if (!handler) {
reject(\`The file at "./${serverOutputPath}/${serverEntry}" did not export a valid request handler. Expected exports: 'app', 'default', or 'reqHandler'.\`);
} else {
process.env.PORT = port;
resolve(handler);
}
});
}, 0);
});
Expand Down

0 comments on commit c0dcbd3

Please sign in to comment.