How to add custom cloud functions when using angular/firebase/angularfire/ssr

Viewed 294

I've run into an issue that seems like there would be an obvious answer but I can't seem to find any documentation or issues about it.

I've created an app in Angular 10 with firebase and angularfire. I added SSR to it using angularfire. I used this tutorial as reference https://dev.to/ankitprajapati/implement-angular-server-side-rendering-and-deploy-angular-universal-app-to-firebase-with-schematics-4nin Everything is running fine including deployment. What I'm having trouble with is adding other cloud functions besides SSR. As far as I can tell, index.js is automatically generated in the dist directory with no way to stop it from being overwritten when running ng deploy.

This is the generated file:

const functions = require('firebase-functions');

// Increase readability in Cloud Logging
require("firebase-functions/lib/logger/compat");

const expressApp = require('./dist/**app-name**/server/main').app();

exports.ssr = functions
 .region('us-central1')
  .runWith({})
  .https
 .onRequest(expressApp);

I have worked around this by first deploying the app as normal with the ssr function, then modifying the generated index.js so the entire contents of the file looks like this with my one function:

exports.addEventToCalendar = require('./functions/addEventToCalendar.ts').addEventToCalendar;

And then I use firebase deploy instead of ng deploy to deploy just the single function

firebase deploy --only functions:addEventToCalendar

This way I have both the SSR function and my addEventToCalendar function available.There's gotta be a better way to do this. Any guidance would be appreciated.

0 Answers
Related