Skip to content

Commit 910a281

Browse files
Merge pull request #177533 from tylerbutler/static-web-apps
New article: Deploy Fluid applications using Azure Static Web Apps
2 parents 164078c + 71a1cd1 commit 910a281

File tree

7 files changed

+197
-0
lines changed

7 files changed

+197
-0
lines changed

articles/azure-fluid-relay/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
href: how-tos/local-mode-with-azure-client.md
3333
- name: 'How to: Write a TokenProvider with an Azure Function'
3434
href: how-tos/azure-function-token-provider.md
35+
- name: 'How to: Deploy Fluid applications using Azure Static Web Apps'
36+
href: how-tos/deploy-fluid-static-web-apps.md
3537
- name: 'How to: Use JWT tokens'
3638
href: how-tos/fluid-json-web-token.md
3739
- name: 'How to: Use test automation with Azure Fluid Relay'

articles/azure-fluid-relay/how-tos/azure-function-token-provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,4 @@ export class AzureFunctionTokenProvider implements ITokenProvider {
158158
## See also
159159

160160
- [Add custom data to an auth token](connect-fluid-azure-service.md#adding-custom-data-to-tokens)
161+
- [How to: Deploy Fluid applications using Azure Static Web Apps](deploy-fluid-static-web-apps.md)
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
title: 'How to: Deploy Fluid applications using Azure Static Web Apps'
3+
description: Detailed explanation about how Fluid applications can be hosted on Azure Static Web Apps
4+
author: sdeshpande3
5+
ms.author: sdeshpande
6+
ms.date: 08/19/2021
7+
ms.topic: article
8+
ms.service: azure-fluid
9+
---
10+
11+
# How to: Deploy Fluid applications using Azure Static Web Apps
12+
13+
This article demonstrates how to deploy Fluid apps using Azure Static Web Apps. The [FluidHelloWorld](https://github.com/microsoft/FluidHelloWorld/tree/main-azure) repository contains a Fluid application called **DiceRoller** that enables all connected clients to roll a dice and view the result. In this how-to, you deploy the DiceRoller application to Azure Static Web Apps using the Visual Studio Code extension.
14+
15+
If you don't have an Azure subscription, [create a free trial account](https://azure.microsoft.com/free).
16+
17+
## Prerequisites
18+
19+
- [GitHub](https://github.com) account
20+
- [Azure](https://portal.azure.com) account
21+
- [Visual Studio Code](https://code.visualstudio.com)
22+
- [Azure Static Web Apps extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurestaticwebapps)
23+
- [Install Git](https://www.git-scm.com/downloads)
24+
25+
[!INCLUDE [fork-fluidhelloworld](../includes/fork-fluidhelloworld.md)]
26+
27+
## Connect to Azure Fluid Relay Service
28+
29+
You can connect to Azure Fluid Relay service by providing the tenant ID and key that is uniquely generated for you when creating the Azure resource. You can build your own token provider implementation or you can use the two token provider implementations that the Fluid Framework provides: **InsecureTokenProvider** and **AzureFunctionTokenProvider**.
30+
31+
To learn more about using InsecureTokenProvider for local development, see [Connecting to the service](connect-fluid-azure-service.md#connecting-to-the-service) and [Authentication and authorization in your app](../concepts/authentication-authorization.md#the-token-provider).
32+
33+
### Using AzureFunctionTokenProvider
34+
35+
**AzureFunctionTokenProvider** is a token provider that does not expose the secret key in client-side code and can be used in production scenarios. This token provider implementation can be used to fetch a token from an HTTPS endpoint that is responsible for signing access tokens with the tenant key. This provides a secure way to generate the token and pass it back to the client app.
36+
37+
```js
38+
import { AzureClient, AzureFunctionTokenProvider } from "@fluidframework/azure-client";
39+
40+
const config = {
41+
tenantId: "myTenantId",
42+
tokenProvider: new AzureFunctionTokenProvider("https://myAzureAppUrl"+"/api/GetAzureToken", { userId: "test-user",userName: "Test User" }),
43+
orderer: "https://myOrdererUrl",
44+
storage: "https://myStorageUrl",
45+
};
46+
47+
const clientProps = {
48+
connection: config,
49+
};
50+
51+
const client = new AzureClient(clientProps);
52+
```
53+
54+
In order to use this token provider, you need to deploy an HTTPS endpoint that will sign tokens, and pass the URL to your endpoint to the AzureFunctionTokenProvider.
55+
56+
### Deploying an Azure Function using Azure Static Web apps
57+
58+
Azure Static Web Apps allow you to develop a full-stack web site without needing to deal with the server-side configuration of an entire web hosting environment. You can deploy Azure Functions alongside your static website. Using this capability, you can deploy an HTTP-triggered Azure Function that will sign tokens.
59+
60+
For more information about deploying Azure Function-powered APIs to your static web app see [Add an API to Azure Static Web Apps with Azure Functions](../../static-web-apps/add-api.md).
61+
62+
> [!NOTE]
63+
> You can use the example Azure Function code in [Implementing an Azure Function to sign tokens](azure-function-token-provider.md#implement-an-azure-function-to-sign-tokens) to implement your function.
64+
65+
Once your Azure Function is deployed, you must update the URL passed to the AzureFunctionTokenProvider.
66+
67+
```js
68+
import { AzureClient } from "@fluidframework/azure-client";
69+
70+
const config = {
71+
tenantId: "myTenantId",
72+
tokenProvider: new AzureFunctionTokenProvider("https://myStaticWebAppUrl/api/GetAzureToken", { userId: "test-user",userName: "Test User" }),
73+
orderer: "https://myOrdererUrl",
74+
storage: "https://myStorageUrl",
75+
};
76+
77+
const clientProps = {
78+
connection: config,
79+
};
80+
81+
const client = new AzureClient(config);
82+
```
83+
84+
Run the `npm run build` command from the root directory to rebuild the app. This will generate a `dist` folder with the application code that should be deployed to the Static Web app.
85+
86+
[!INCLUDE [sign-in-extensions](../includes/sign-in-extensions.md)]
87+
88+
## Create a static web app
89+
90+
1. Inside Visual Studio Code, select the Azure logo in the Activity Bar to open the Azure extensions window.
91+
92+
:::image type="content" source="../../static-web-apps/media/getting-started/extension-azure-logo.png" alt-text="An image of the Azure Logo on a white background.":::
93+
94+
> [!NOTE]
95+
> You must sign in to Azure and GitHub in Visual Studio Code to continue. If you are not already authenticated, the extension will prompt you to sign in to both services during the creation process.
96+
97+
1. Under the *Static Web Apps* label, select the **plus sign**.
98+
99+
:::image type="content" source="../../static-web-apps/media/getting-started/extension-create-button.png" alt-text="An image of the Static Web Apps extension UI, highlighting the create button.":::
100+
101+
> [!NOTE]
102+
> The Azure Static Web Apps Visual Studio Code extension streamlines the creating process by using a series of default values. If you want to have fine-grained control of the creation process, open the command palate and select **Azure Static Web Apps: Create Static Web App... (Advanced)**.
103+
104+
1. The command palette opens at the top of the editor and prompts you to select a subscription name.
105+
106+
Select your subscription and press <kbd>Enter</kbd>.
107+
108+
:::image type="content" source="../../static-web-apps/media/getting-started/extension-subscription.png" alt-text="An image of the Azure subscription selection UI, which shows a single subscription to be selected.":::
109+
110+
1. Next, name your application.
111+
112+
Type **my-first-static-web-app** and press <kbd>Enter</kbd>.
113+
114+
:::image type="content" source="../../static-web-apps/media/getting-started/extension-create-app.png" alt-text="An image of the Static Web Apps extension UI, which shows a text box to enter the name of the application.":::
115+
116+
1. Select a region close to you.
117+
118+
> [!NOTE]
119+
> Azure Static Web Apps globally distributes your static assets. The region you select determines where your
120+
> optional staging environments and API function app will be located.
121+
122+
1. Set other deployment options.
123+
124+
- When asked to select a build preset to configure default project structure, select **Custom**.
125+
- Location of application code: `/`
126+
- Location of Azure Function code: `api`
127+
128+
1. Once the app is created, a confirmation notification is shown in Visual Studio Code.
129+
130+
:::image type="content" source="../../static-web-apps/media/getting-started/extension-confirmation.png" alt-text="An image of the notification shown in Visual Studio Code when the app is created. The notification reads: Successfully created new static web app my-first-static-web-app. GitHub Actions is building and deploying your app, it will be available once the deployment completes.":::
131+
132+
As the deployment is in progress, the Visual Studio Code extension reports the build status to you.
133+
134+
:::image type="content" source="../../static-web-apps/media/getting-started/extension-waiting-for-deployment.png" alt-text="An image of the Static Web Apps extension UI, which shows a list of static web apps under each subscription. The highlighted static web app has a status of Waiting for Deployment displayed next to it.":::
135+
136+
Once the deployment is complete, you can navigate directly to your website.
137+
138+
1. To view the website in the browser, right-click on the project in the Static Web Apps extension, and select **Browse Site**.
139+
140+
:::image type="content" source="../../static-web-apps/media/getting-started/extension-browse-site.png" alt-text="An image of the menu that is shown when right-clicking on a static web app. The Browse Site option is highlighted.":::
141+
142+
1. The location of your application code, Azure Function, and build output is part of the `azure-static-web-apps-xxx-xxx-xxx.yml` workflow file located in the `/.github/workflows` directory. This file is automatically created when create the Static Web app. It defines a GitHub Action to build and deploy your Static Web app.
143+
144+
145+
## Clean up resources
146+
147+
If you're not going to continue to use this application, you can delete the Azure Static Web Apps instance through the extension.
148+
149+
In the Visual Studio Code Explorer window, return to the _Static Web Apps_ section and right-click on **my-first-static-web-app** and select **Delete**.
150+
151+
:::image type="content" source="../../static-web-apps/media/getting-started/extension-delete.png" alt-text="An image of the menu that is shown when right-clicking on a static web app. The Delete option is highlighted.":::
11.6 KB
Loading
5.09 KB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
author: tylerbutler
3+
ms.service: azure-fluid
4+
ms.topic: include
5+
ms.date: 10/25/2021
6+
ms.author: tylerbu
7+
---
8+
9+
## Fork and clone the repository
10+
11+
Navigate to <https://github.com/microsoft/FluidHelloWorld> and click the **Fork** button to create your own fork of the
12+
FluidHelloWorld repo.
13+
14+
Then clone your fork to your local machine using the following command.
15+
16+
```shell
17+
git clone -b main-azure https://github.com/<YOUR_GITHUB_ACCOUNT_NAME>/FluidHelloWorld.git
18+
```
19+
20+
Make sure to replace `<YOUR_GITHUB_ACCOUNT_NAME>` with your GitHub username.
21+
22+
Next, open Visual Studio Code and go to **File > Open Folder** to open the cloned repository in the editor.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
author: tylerbutler
3+
ms.service: azure-fluid
4+
ms.topic: include
5+
ms.date: 10/25/2021
6+
ms.author: tylerbu
7+
---
8+
9+
## Sign in to Azure
10+
11+
If you already use the Azure service extensions, you should already be logged in and can skip this step.
12+
13+
Once you've installed an extension in Visual Studio Code, you need to sign into your Azure account.
14+
15+
1. In Visual Studio Code, select the **Azure** explorer icon, then select **Sign in to Azure**, and follow the prompts.
16+
17+
![Sign in to Azure through VS Code](../images/azure-sign-in.png)
18+
19+
2. After signing in, verify that the email address of your Azure account appears in the Status Bar and your subscription(s) appears in the **Azure** explorer:
20+
21+
![VS Code Azure explorer showing subscriptions](../images/azure-subscription-view.png)

0 commit comments

Comments
 (0)