Step by step guide for deploying an Angular 9 universal app with Firebase functions

After updating to the latest Angular version 9, I created an app and made it universal using the following commands:

ng add @nguniversal/express-engine

npm run build:ssr && npm run serve:ssr

Now, a 'dist' folder has been created with both browser and server folders in it. However, no 'server.js' file was generated in the root directory of 'dist', and the webpack config file was also missing when building the app with Angular 9.

Please provide guidance on how I can deploy my new app built on Angular 9 Universal to Firebase Cloud Functions and Hosting.

Answer №1

When working with Angular 9, your build structure will look like this:

 dist            
  ├── server            
  |    └── main.js and additional files such as Firebase analytics content       
  └── browser                
       └── index.html and all browser-related files 

To test this setup, run the following command from your project's root directory:

node dist/server

This will execute the main.js file in the server folder and serve your app locally. Information about the localhost URL with the port will be displayed on the screen.

For deployment to Firebase, include the following code:

import * as functions from 'firebase-functions';
import * as path from 'path';

const app = require(path.resolve(__dirname, "./dist/server/main")).app; // adjust the path based on your project structure
const myApp = functions.https.onRequest(app());

You will then have a function named myApp that allows access to your Angular SSR App.

[UPDATE]

The exact location of initializing your functions does not matter as long as the path of dist/server/main is correct in the myApp function.

Another important detail is updating the hosting field in your package.json file with the following configuration:

  ...
  "hosting": [{
        "target": "app",
        "public": "/dist/browser", // adjust it according to your directory structure
        "rewrites": [{
            "source": "**",
            "function": "myApp"
        }]
  }]
  ...

I hope this information proves helpful 😉

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Optional Route Parameters in Angular with @ngrx

Just like the ngrx/example-app, I am in the process of developing a user interface that allows users to search for specific items by inputting a text string. I want to enhance the user experience by updating the URL with an optional parameter (query=searc ...

Establishing connection between a MEAN stack application and MongoDB hosted on AWS

I am currently developing a MEAN stack application. MongoDB is operational on AWS, and I have successfully connected to it using Robo 3T. While attempting to code the connection in my express angular application, I keep encountering a connection timeout e ...

Various ways to arrange projects while creating an Angular application with a distinct Spring backend

I am currently working on creating a web page that involves separating Database, Backend, and Frontend, and establishing communication between them using REST. However, I am facing some confusion regarding how to best structure the project(s). From what I ...

Unable to fetch information from the controllerAPI function within the tsx file due to a Module Parse error

I am currently working on fetching records from a database using ControllerApi and displaying them through React. The code snippet below is from a file with a *.tsx extension: import React, { useState } from 'react'; import ReactDOM from 'r ...

Testing to submit a form using ReactiveForm can be done by reloading the form while it is being submitted

A tutorial I came across titled "Make Your Angular Form’s Error Messages Magically Appear" sparked the beginning of my journey. The tutorial featured a simple form with just one input field and one button. To trigger additional events on a lower level, I ...

The issue arises when using Angular Material as it seems that passing a data object to a matdialog dialog

After reviewing multiple posts and carefully examining the process of passing data from an Angular Component to MatDialog, I am facing an issue where 'undefined' is being returned when the dialog loads. Below is the code snippet I have been work ...

Is it possible to integrate an Angular-CLI 8 library into an Angular 2, 4, 5, 6, or 7 application without any problems? Would it be compatible

I have been developing and distributing an Angular library via NPM using custom scripts during the Angular 5 era. Fortunately, this library is free from any challenging peer dependencies and works seamlessly with Angular 5 through 8 applications. Now, I a ...

Exploring the Best Times to Utilize React.PropsWithChildren

It's interesting how in what appears to be two identical setups, I encountered different behaviors. On one system, I could use the following code snippet: <MyApp accountId={this.props.accountId} children={toggleButton} /> The M ...

The Firebase timestamp is not compatible with the SimpleDateFormat for retrieving timestamps

After spending a considerable amount of time working on the implementation of the timestamp feature, I have managed to save it in Firebase along with other data for the pictures. However, I am facing an issue where the timestamp is not displaying correctly ...

Angular's failure to function properly

I am currently working on developing a web application using Angular and an NX workspace. The application was created within the NX workspace environment. However, I keep encountering the following error when running the application. Despite attempting to ...

Encountering a problem during the installation of Angular CLI on a consistent Node.js

Encountering a problem while trying to Install Angular CLI. I have exhausted all possible solutions such as clearing cache, uninstalling and reinstalling Node, and manually deleting the npm-cache folder in Appdata. Below is the error I encounter when run ...

There is no such property - Axios and TypeScript

I am attempting to retrieve data from a Google spreadsheet using axios in Vue3 & TypeScript for the first time. This is my initial experience with Vue3, as opposed to Vue2. Upon running the code, I encountered this error: Property 'items' does ...

combine several JSON files into one JSON object with their respective file paths as keys

I have multiple JSON files that I need to merge into a single JSON file. To organize them effectively, I want to enclose each file under a unique key based on its path so that accessing specific files becomes easier in the combined JSON file. const jsonF ...

Error in React Typescript: Attempted to access properties of an undefined value

The new Object is displayed in the console but I'm still encountering an error const GetNo = (): string => { console.log(record); if (record.no !== "") return record.no; //<-- Cannot read properties of und ...

What is the procedure for obtaining FlowNode in the typescript ast api?

Trying to access and resolve foo and bar from the nodes variable. Upon examination in ts-ast-viewer, it is evident that TypeScript recognizes foo and bar within the nodes node under the FlowNode section (node -> initializer -> elements -> escaped ...

Angular observable goes unnoticed

I'm venturing into creating my own observable for the first time, and I'm running into issues. The data is visible in the console, but it doesn't show up when the component loads. Can anyone help me troubleshoot this problem? Here's a ...

Dispatch an item containing a list within a list

Currently developing a web application utilizing Angular for user input of two arrays and a matrix, which is then sent to Java for calculations. Utilizing FormGroup for the form fields, the values sent to the server appear as follows: object { targetFuncti ...

Is it possible to retrieve data from Firebase using useEffect only once?

I am currently delving into the world of React and Firebase, working on my first "real" project. The connection to firebase appears to be successful as I can see the data logged in the console. However, when I attempt to manipulate the data, it disappears ...

An error has occurred in the Angular application while trying to access the 'name' property in the AppComponent_Template

I'm encountering a challenge in my Angular application where I am receiving the following error message: javascript Copy code ERROR TypeError: Cannot read properties of undefined (reading 'name') This issue is present in the app.component. ...

Tips for fixing the issue: How to handle the notification that an error event has already been emitted on the socket?

I'm currently developing my first Angular app by following the instructions provided at this link. However, upon running the app, I encountered the following errors: (node:4064) Warning: An error event has already been emitted on the socket. Please ...