Skip to content

Latest commit

 

History

History
116 lines (76 loc) · 6.98 KB

node.md

File metadata and controls

116 lines (76 loc) · 6.98 KB

Node.js Forge App with Azure App Service

This is to walk you through the steps to deploy a Node.js sample Forge App to Azure App Service as a Web App with the Azure Web Portal and Git.

For this tutorial, we will be using our ViewHubModels sample as described in previous chapters. You may retrieve the full sample from our Github repo. The same steps should also work for View Models tutorial code.

Before you start, sign in or sign up for Microsoft Azure Computing Platform & Services and create a trial account, it includes $200 credit and free for 12 months

Prerequisites

Most steps can be done via Web Portal, but Azure CLI is required.

Create an Azure Web App

There are 2 ways to create an app: using the Web Portal and with CLI.

1. Create an app with Web Portal

  • Create a Resource Group and a Web App

  • Set the Runtime Stack to NodeJs and click Create

  • It may take a while for the app to be created, once all done, navigate to the app to review its settings

2. Create an App with Azure CLI

  • Create a Resource Group (or use existing) and a Web App with commands below:
# login with credentials explicitly or simply use 'azure login' to log in with a browser session or authorisation code
az login -u <username> -p <password>

# Create a Resource Group
az group create --location westus --name myResourceGroup

# Create an App Service Plan in free tier
az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku FREE

# Create a Web App
az webapp create --name <nameofyourapp> --plan myAppServicePlan --resource-group myResourceGroup

Deploy the App

For this tutorial, we are going with Local Git to deploy our code. This can done using the Web Portal and with CLI

1. Deploy using Web Portal

  • Navigate to the Deployment Center to set up deployment settings

  • Choose your build server

  • Set deployment source to Local Git

  • Click the highlighted button on right top to open the Azure CLI, run az webapp deployment user set --user-name $username --password $password to configure deployment credentials and record the resulting Git url

  • Set up the environment variables with your Forge App credentials (FORGE_CLIENT_ID and FORGE_CLIENT_SECRET) and the callback url (following pattern http://<nameofyourapp>.azurewebsites.net/api/forge/callback/oauth)

2. Deploy using CLI

# Set the account-level deployment credentials
az webapp deployment user set --user-name $username --password $password

# Configure local Git and get deployment URL
echo $(az webapp deployment source config-local-git --name <nameofyourapp> --resource-group <nameofyourresourcegroup> --query url --output tsv)

# Set up the environment variables
az webapp config appsettings set -g MyResourceGroup -n <nameofyourapp> --settings FORGE_CLIENT_ID=<yourForgeAppClientID> FORGE_CLIENT_SECRET=<yourForgeAppSecret> FORGE_CLIENT_SECRET=<yourForgeAppSecret> FORGE_CALLBACK_URL=<yourCallbackURL>
  • Push your local repo to your Azure Web App with Git CLI or your favorite Git client
# Add the Azure remote to your local Git respository and push your code
cd /path/to/local/repo
git remote add azure <giturlofyourapp>
git push azure master # use 'git push azure <nameofyourbranch>:master' if you would like to push other local branches than master

The app dashboard should look like:

Done! Open the app url to see our app in action.

3. Other Deployment Options

Demo Screencast

Watch this screencast demonstrating the above steps on the Azure Portal and CLI (the screencast is based on Bash but the commands involved would have been identical on Windows CLI and Powershell. And you can run Bash on Windows! See this or this as part of Git or even try the Linux Subsystem)

viewNodejs

Further Readings