Building the backend

In this lesson you will prepare the application backend an entry gate for communicating with persistance layer and hosting Angular application bundle.

Building the Backend#

Now implement the backend which will be used to host your Angular application on production. Add the necessary dependency to your Angular project:

Create a new file called backend.ts in your project root directory (next to the package.json file) and add the following code to it:

The code above serves the business logic from api.ts under the /api/* endpoints (you will add it soon).

The code above serves all traffic with static files available in the dist folder where your Angular application will reside.

Compiler and package.json scripts#

The final step is to set up compiler options for the backend. Create a new file called tsconfig.backend.json and add the following configuration to it:

Last but not least, adjust the scripts section in the package.json file by changing the start script and adding the build:backend script:

Testing the backend#

Build and run the backend using the following commands:

Navigate with your browser to http://localhost. You should see your Angular application skeleton:

Please select a discussion on the left.