TL;DR: This blog contains the step-by-step procedures for deploying the full-stack web app built with Angular and GraphQL on both IIS and Azure App Service. It covers preparing the application and enabling IIS on Windows, configuring Azure resources, and troubleshooting common hosting issues.
Welcome to our exciting journey of building a full-stack web application using Angular and GraphQL. In the previous article of this series, we added the watchlist feature to our application, allowing users to add or remove movies from their watchlist. In this article, we will learn to deploy our MovieApp on both IIS and Azure App Service.
Let’s get started!
To prepare our app for deployment, we must ensure it builds successfully. The Angular app has a budget for the bundle size in the angular.json file.
To run the application, navigate to the clientApp folder and use the following command.
ng build
You will see a bundle size exceeded error, as shown in the following screenshot.
This error indicates that the current bundle size is 4.94 MB, exceeding the allotted 1 MB budget. To resolve this issue, update the bundle budget to 5 MB in the angular.json file.
"production": { "budgets": [ { "type": "initial", "maximumWarning": "500kb", "maximumError": "5mb" // Update this line. }, // Existing code. ], },
Next, update the GraphQL server endpoint URL in the src\app\graphql.module.ts file. Refer to the following code to update the URL.
const uri = 'https://localhost:7214/graphql'; // Current code. const uri = 'graphql'; // update to this.
We’re hosting the GraphQL server and the Angular client app on the same server. As a result, the base URL for the server and client will be identical. This modification ensures that our client can connect with the server using the graphql endpoint name on the same base URL.
However, if your GraphQL server and Angular client app are hosted on different servers, you’ll need to provide the complete GraphQL server URL.
To enable Internet Information Services (IIS) on Windows 11, follow these steps:
The URL rewrite module allows site administrators to create custom rules for implementing user-friendly and SEO-enhanced URLs. To get started, check out the detailed instructions in the Microsoft documentation.
Follow these steps to install it:
To power your app with the .NET Runtime and IIS support, you’ll need the .NET Core Hosting Bundle. First, navigate to the .NET downloads page and click on the latest stable version of .NET. For our app, we are using .NET 8.0, so select that option.
On the download page, you’ll find a table under the Download .NET (Current) heading listing .NET versions. Focus on the Run apps – Runtime column to find the row for the specific .NET Core runtime version you need.
In that row, under the Windows section, locate the Hosting Bundle link. This link will take you to the download page for the .NET Core Hosting Bundle for Windows.
Note:
1. Install the .NET Core hosting bundle after installing IIS.
2. Restart your machine after installing the .NET Core Hosting Bundle.
After setting up IIS and installing the necessary dependencies, it’s time to publish the MovieApp project:
If there are no build errors, the app will be successfully published to the specified folder path.
To start with IIS, open the Windows 11 search box, type IIS, and select Internet Information Services (IIS) to launch the web server manager.
To create a website:
Next, you’ll need to configure the application pool:
To configure the host file on your machine in Windows 11, follow these steps:
127.0.0.1 movieapp.com
After executing the previous code examples, open a browser and navigate to the URL http://movieapp.com/. You will see the output as shown in the following image.
Let’s address the common issues related to hosting a .NET app.
If you encounter a DNS not found error when trying to open your website, try the following:
This error occurs due to invalid configuration data. To resolve it:
Your website loads, but data isn’t populated, and you encounter a 500 internal server error. To resolve this:
Note: If you republish the app, remember to refresh your website and the application pool in IIS.
With these issues addressed, we’ve successfully deployed the app to IIS. Now, let’s see how to deploy it to Azure App Service.
Before proceeding, ensure you have an Azure subscription account.
We will create an SQL Server on Azure to handle our database operations.
Follow these steps:
A new page with the title “Create SQL Database” will appear. On this page, you will be asked to furnish the details for your SQL database.
Provide the details in the basics tab as follows:
Click on Create new to set up a new server for your database. In the subsequent window, provide the following details.
With your database now created, the next step is to set up access so that you can connect to it from your local machine and other Azure resources, like the Azure App Service.
To allow the required access to the database:
To connect to this database, you will need a connection string. First, click on Connection strings in the Settings menu on the left side of the page. Then, select the ADO.NET tab and copy the provided connection string.
Next, open the appsettings.json file in your project and replace the existing local database connection string with the connection string of Azure SQL Server.
Refer to the following code.
"ConnectionStrings": { "DefaultConnection": "Server=tcp:moviedbserver.database.windows.net,1433;Initial Catalog=MovieDB;Persist Security Info=False;User ID={YourUserID};Password={YourPassword};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" },
In Azure SQL Database, the tables needed for our application aren’t automatically created. Let’s walk through the process of creating them.
Launch the SQL Server Management Studio and connect to your Azure SQL Server by providing the following details:
When connecting from your local machine, you’ll be prompted to set up a firewall rule. Follow the steps mentioned below:
Once connected, create all the necessary tables in the database. The SQL scripts for table creation are in the Configure the database section of Part 1 of this series. Execute these scripts to generate the tables.
Now, launch the application from Visual Studio. Initially, it will display no movie data, but you can view genre data. Refer to the following image.
To publish your MovieApp project:
In the new window, provide the following details for your app service:
Then, click Create to initiate the creation of your Azure App Service instance. Once the app service is created, select its name and click Finish.
On the next page, review all the provided information. Click Publish at the top to start building and publishing your app. After the publication is successful, the URL will automatically launch in your machine’s default browser.
The website URL will be <app service name>.azurewebsites.net, and the webpage looks like the following image.
Since the database tables are empty, no data is displayed on the page. To correct this, add an entry for the Admin user in the UserMaster database, as described in the Update the database section of Part 5 of this series.
Log in as the admin user to access the app and add some movie data to populate the database tables. Once you’ve added data, you can validate that the app is works as expected.
The application created in this series of articles is available at MovieApp.
For more details, refer to the complete source code for the full-stack web app with Angular and GraphQL on GitHub.
Thank you for reading this article. In it, we learned to configure the IIS on a Windows machine and deploy a full-stack .NET app on it. We created an SQL Server database on Azure and configured it to be used as the database provider in our app. Finally, we deployed the app on the Azure app service.
Whether you’re already a valued Syncfusion user or new to our platform, we extend an invitation to explore our Angular components with the convenience of a free trial. This trial allows you to experience the full potential of our components to enhance your app’s user interface and functionality.
Our dedicated support system is readily available if you need guidance or have any inquiries. Contact us through our support forum, support portal, or feedback portal. Your success is our priority, and we’re always delighted to assist you on your development journey!