You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/howto-integrate-app-gateway.md
+25-25Lines changed: 25 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ The diagram illustrates what we are going to achieve in step 1.
28
28
### Create an Azure Application Gateway instance
29
29
On Azure portal, search for Azure Application Gateway and follow the steps to create a resource. Key steps are highlighted in the diagram.
30
30
31
-
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-1.jpg" alt-text="Create an Application Gateway resource - basics.":::
31
+
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-1.jpg" alt-text="Screenshot showing how to create an Application Gateway resource - basics.":::
32
32
33
33
A Virtual Network is needed for Azure resources to securely communicate with each other. Azure Application Gateway requires a dedicated subnet, which is what we created. For the sake of this guide, in step 1, your Azure Application Gateway resource forwards traffic to your Web PubSub resource via the **public internet**. In step 2, we create another subnet that houses a Web PubSub resource so that your Azure Application Gateway forwards traffic to your Web PubSub resource securely through a Virtual Network.
Frontends are the IP addresses of your Azure Application Gateway. Since we use Azure Application Gateway as the single point of contact for our web clients, we need to create a public IP for it.
42
42
43
-
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-2.jpg" alt-text="Create an Application Gateway resource - create public IP.":::
43
+
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-2.jpg" alt-text="Screenshot showing how to create an Application Gateway resource - create public IP.":::
44
44
45
45
Backends are the resources your Application Gateway resource can send traffic to. In our case, we have one target, our Web PubSub resource. Find the **host name** of an existing Web PubSub resource you intend to use to follow this guide on Azure portal. It should look like this, `xxxx.webpubsub.azure.com`.
46
46
47
-
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-3.jpg" alt-text="Create an Application Gateway resource - create a backend pool.":::
47
+
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-3.jpg" alt-text="Screenshot showing how to create an Application Gateway resource - create a backend pool.":::
48
48
49
49
With both the frontends and backends set up, we need to configure a routing rule that connects the frontends and the backends. The routing rule tells Application Gateway how to route traffic and to where.
50
50
51
51
First, we set up a listener. This configuration tells Application Gateway to listen for HTTP traffic on PORT 80.
52
52
53
-
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-4.jpg" alt-text="Create an Application Gateway resource - create a routing rule, listener.":::
53
+
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-4.jpg" alt-text="Screenshot showing how to create an Application Gateway resource - create a routing rule, listener.":::
54
54
55
55
Second, we set up the backend targets. We configure backend targets to the backend pool we created earlier, which is our Web PubSub resource. Additionally, we need to specify how Application Gateway should forward the traffic. You accomplish it through **backend settings**.
56
56
57
-
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-5.jpg" alt-text="Create an Application Gateway resource - create a routing rule, backend targets.":::
57
+
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-5.jpg" alt-text="Screenshot showing how to create an Application Gateway resource - create a routing rule, backend targets.":::
58
58
59
59
60
60
Web PubSub service only accepts HTTPs traffic. So we instruct Application Gateway to communicate with Web PubSub using HTTPs. To keep this guide focused, we let Application Gateway to pick the host. The recommended practice is to set up a Custom Domain in production.
61
61
62
-
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-6.jpg" alt-text="Create an Application Gateway resource - create a routing rule, backend settings.":::
62
+
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-6.jpg" alt-text="Screenshot showing how to create an Application Gateway resource - create a routing rule, backend settings.":::
63
63
64
64
When the three components are configured, you should see something like the screenshot. You can visualize the flow of traffic through Application Gateway as such:
65
65
1. Web clients send requests to your public IP of your Application Gateway resource.
66
66
2. Application Gateway routes traffic by consulting the user-configured routing rules.
67
67
3. When the routing rule matches, the traffic is directed to the designated backend target.
68
68
69
-
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-7.jpg" alt-text="Create an Application Gateway resource - finished.":::
69
+
:::image type="content" source="media/howto-integrate-app-gateway/create-resource-step-7.jpg" alt-text="Screenshot showing how to create an Application Gateway resource - finished.":::
70
70
71
71
One thing that is worth highlighting is that you configure **non-WebSocket** connections exactly the same way. You can learn more about [Application Gateway's native support for proxying WebSocket connections](../application-gateway/features.md)
On Azure portal, find the `connection string` of your Web PubSub resource.
150
-
:::image type="content" source="media/howto-integrate-app-gateway/web-pubsub-connection-string.jpg" alt-text="Get the connection string of a Web PubSub resource.":::
150
+
:::image type="content" source="media/howto-integrate-app-gateway/web-pubsub-connection-string.jpg" alt-text="Screenshot showing how to get the connection string of a Web PubSub resource.":::
151
151
152
152
```bash
153
153
npm install
@@ -205,7 +205,7 @@ Copy the code to `index.html`
205
205
##### Run the client program
206
206
Open your preferred web browser and visit `http://localhost:3000`, where our server is listening.
207
207
208
-
:::image type="content" source="media/howto-integrate-app-gateway/local-browser-client-direct.jpg" alt-text="A browser client directly connected with Web PubSub resource and the server app running locally.":::
208
+
:::image type="content" source="media/howto-integrate-app-gateway/local-browser-client-direct.jpg" alt-text="Screenshot showing a browser client directly connects with Web PubSub resource and the server app running locally.":::
209
209
210
210
Make sure you still have `publish.js`running. If you inspect the page, open the Network and Console panels, you should see that the client is successfully connected with your Web PubSub resources and are getting the broadcasted messages.
211
211
@@ -240,7 +240,7 @@ Three points to note.
240
240
241
241
Open your browser and visit `http://localhost:3000` again, you can verify that the WebSocket is successfully proxied through Application Gateway and receives messages from Application Gateway roughly every 2 seconds.
242
242
243
-
:::image type="content" source="media/howto-integrate-app-gateway/local-browser-client-indirect.jpg" alt-text="Screenshot of a browser client indirectly connected with Web PubSub resource and the server app running locally.":::
243
+
:::image type="content" source="media/howto-integrate-app-gateway/local-browser-client-indirect.jpg" alt-text="Screenshot showing a browser client indirectly connects with Web PubSub resource and the server app running locally.":::
244
244
245
245
### Recap of step 1
246
246
We reached the end of step 1. If you have been following step 1, you should see that your Web PubSub resource is accessible directly by your web clients **and** indirectly through Application Gateway. You also saw Application Gateway's native support for WebSocket in action. Enabling it doesn't require any configuration changes. We only need to make sure that a web client points to an Application Gateway endpoint. The rest of the access URL generated from Web PubSub service SDK should remain unchanged.
@@ -252,7 +252,7 @@ The outcome of step 1 is that your Web PubSub resource is accessible through bot
252
252
253
253
Web PubSub service supports configuring access controls. One such configuration is to disable access from public internet. Make sure to hit "save" when you're done.
254
254
255
-
:::image type="content" source="media/howto-integrate-app-gateway/disable-public-access.jpg" alt-text="Disable public access of Web PubSub.":::
255
+
:::image type="content" source="media/howto-integrate-app-gateway/disable-public-access.jpg" alt-text="Screenshot showing how to disable public access of Web PubSub.":::
256
256
257
257
Now if you run the same command, instead of seeing "Invalid hub name" as before, you see `403 Forbidden`.
258
258
```bash
@@ -272,25 +272,25 @@ In step 1, we created a subnet that houses Application Gateway. Application Gate
272
272
273
273
Locate the Virtual Network resource that we created earlier and create a new subnet.
274
274
275
-
:::image type="content" source="media/howto-integrate-app-gateway/create-another-subnet.jpg" alt-text="Create another subnet.":::
275
+
:::image type="content" source="media/howto-integrate-app-gateway/create-another-subnet.jpg" alt-text="Screenshot showing how to create another subnet.":::
276
276
277
277
### Create a Private Endpoint for your Web PubSub resource
278
278
Locate your Web PubSub resource on Azure portal and go to "Networking" blade.
279
-
:::image type="content" source="media/howto-integrate-app-gateway/web-pubsub-create-private-endpoint-step-1.jpg" alt-text="Create a separate subnet.":::
279
+
:::image type="content" source="media/howto-integrate-app-gateway/web-pubsub-create-private-endpoint-step-1.jpg" alt-text="Screenshot showing how to create a separate subnet.":::
280
280
281
281
Create a Private Endpoint in the same region as your Web PubSub resource.
282
-
:::image type="content" source="media/howto-integrate-app-gateway/web-pubsub-create-private-endpoint-step-2.jpg" alt-text="Create an Private Endpoint for Web PubSub resource.":::
282
+
:::image type="content" source="media/howto-integrate-app-gateway/web-pubsub-create-private-endpoint-step-2.jpg" alt-text="Screenshot showing how to create an Private Endpoint for Web PubSub resource.":::
283
283
284
284
Select the separate subnet we just created.
285
-
:::image type="content" source="media/howto-integrate-app-gateway/web-pubsub-create-private-endpoint-step-3.jpg" alt-text="Place Web PubSub's Private Endpoint in the newly created subnet.":::
285
+
:::image type="content" source="media/howto-integrate-app-gateway/web-pubsub-create-private-endpoint-step-3.jpg" alt-text="Screenshot showing how to place Web PubSub's Private Endpoint in the newly created subnet.":::
:::image type="content" source="media/howto-integrate-app-gateway/web-pubsub-create-private-endpoint-step-4.jpg" alt-text="Screenshot showing how to enableprivateDNS integration.":::
289
289
290
290
291
291
### Refresh the backend pool of your Application Gateway resource
292
292
Your Application Gateway resource doesn't know that you created a Private Endpoint for your Web PubSub resource. Locate your Application Gateway resource and refresh the backend pools.
:::image type="content" source="media/howto-integrate-app-gateway/refresh-backend-pools.jpg" alt-text="Screenshot showing how to refresh backend pools.":::
294
294
295
295
Now if you run this command again, you should see "Invalid hub name" again, which is expected. It shows that Application Gateway proxies through Virtual Network instead of the public internet.
296
296
```bash
@@ -303,9 +303,9 @@ Because the public access to your Web PubSub resource is disabled, our local `pu
303
303
#### Deploy a Web App as a ZIP file
304
304
Before we can ZIP up our source code and deploy it to Azure App Service, we need to make a small change to the client code. The `/negotiate` endpoint will no longer be served from `localhost`.
305
305
306
-
Locate `index.html` in the public folder, and change the line where `endpoint` variable is declared.You need to replace it with the domain name of your Web App.
306
+
Locate `index.html` in the public folder, and change the line where `endpoint` variable is declared.You need to replace it with the domain name of your Web App.
307
307
308
-
:::image type="content" source="media/howto-integrate-app-gateway/web-app-domain-name.jpg" alt-text="The domain name of Web App resource.":::
308
+
:::image type="content" source="media/howto-integrate-app-gateway/web-app-domain-name.jpg" alt-text="Screenshot showing where to get the domain name of Web App resource.":::
309
309
310
310
```html
311
311
<script>
@@ -352,14 +352,14 @@ App Service requires a dedicated subnet in your Virtual Network. Go to your Virt
352
352
353
353
Once a new subnet is created, go to the "Networking" blade of your Web App resource and enable Virtual Network integration.
:::image type="content" source="media/howto-integrate-app-gateway/web-app-enable-vnet-step-2.jpg" alt-text="Screenshot showing how to enable Virtual Network integration - step 2.":::
359
359
360
360
#### Turn off automatic HTTP redirect
361
361
By default, Web App redirects HTTP traffic to HTTPs. We need to disable this default behavior. This is not recommended for production workload.
362
-
:::image type="content" source="media/howto-integrate-app-gateway/web-app-turn-off-https-redirect.jpg" alt-text="Turn off automatic HTTPs redirect.":::
362
+
:::image type="content" source="media/howto-integrate-app-gateway/web-app-turn-off-https-redirect.jpg" alt-text="Screenshot showing how to turn off automatic HTTPs redirect.":::
363
363
364
364
### Verify that everything works
365
365
So far in step 2, you
@@ -373,9 +373,9 @@ So far in step 2, you
373
373
374
374
Now, open your web browser and enter the domain name of your Web App. If you inspect the page, open the Network panel, you see that the client goes to Web App for the access token and then uses the token to establish a WebSocket connection with Application Gateway.
375
375
376
-
:::image type="content" source="media/howto-integrate-app-gateway/web-app-serves-access-token.jpg" alt-text="Get an access token from a Web App.":::
376
+
:::image type="content" source="media/howto-integrate-app-gateway/web-app-serves-access-token.jpg" alt-text="Screenshot showing how to get an access token from a Web App.":::
377
377
378
-
:::image type="content" source="media/howto-integrate-app-gateway/connect-with-web-pubsub-indirect-azure.jpg" alt-text="Successfully establish a WebSocket connection through Application Gateway.":::
378
+
:::image type="content" source="media/howto-integrate-app-gateway/connect-with-web-pubsub-indirect-azure.jpg" alt-text="Screenshot showing successfully established a WebSocket connection through Application Gateway.":::
379
379
380
380
If you have the Console panel open, you see the broadcasted messages, as well.
381
-
:::image type="content" source="media/howto-integrate-app-gateway/connect-with-web-pubsub-indirect-azure-messages.jpg" alt-text=" Getting messages from Application Gateway, which proxies traffic for Web PubSub.":::
381
+
:::image type="content" source="media/howto-integrate-app-gateway/connect-with-web-pubsub-indirect-azure-messages.jpg" alt-text="Screenshot showing getting messages from Application Gateway, which proxies traffic for Web PubSub.":::
0 commit comments