Skip to content

Commit ab4a37c

Browse files
authored
Merge pull request #199529 from dlepow/cors
[APIM] CORS configuration in self-hosted portal
2 parents eccad6c + d26e2e9 commit ab4a37c

File tree

1 file changed

+25
-40
lines changed

1 file changed

+25
-40
lines changed

articles/api-management/developer-portal-self-host.md

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
2-
title: Self-host the developer portal
2+
title: Self-host the API Management developer portal
33
titleSuffix: Azure API Management
4-
description: Learn how to self-host the API Management developer portal.
4+
description: Learn how to self-host the developer portal for Azure API Management.
55
author: dlepow
66
ms.author: danlep
7-
ms.date: 04/15/2021
7+
ms.date: 06/07/2022
88
ms.service: api-management
99
ms.topic: how-to
1010
---
1111

1212
# Self-host the API Management developer portal
1313

14-
This tutorial describes how to self-host the [API Management developer portal](api-management-howto-developer-portal.md). Self-hosting gives you flexibility to extend the developer portal with custom logic and widgets that dynamically customize pages on runtime. You can self-host multiple portals for your API Management instance, with different features. When you self-host a portal, you become its maintainer and you are responsible for its upgrades.
14+
This tutorial describes how to self-host the [API Management developer portal](api-management-howto-developer-portal.md). Self-hosting gives you flexibility to extend the developer portal with custom logic and widgets that dynamically customize pages on runtime. You can self-host multiple portals for your API Management instance, with different features. When you self-host a portal, you become its maintainer and you're responsible for its upgrades.
1515

1616
The following steps show how to set up your local development environment, carry out changes in the developer portal, and publish and deploy them to an Azure storage account.
1717

@@ -27,7 +27,7 @@ To set up a local development environment, you need to have:
2727
- An Azure storage account with [the static websites feature](../storage/blobs/storage-blob-static-website.md) enabled. See [Create a storage account](../storage/common/storage-account-create.md).
2828
- Git on your machine. Install it by following [this Git tutorial](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
2929
- Node.js (LTS version, `v10.15.0` or later) and npm on your machine. See [Downloading and installing Node.js and npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
30-
- Azure CLI. Follow [the Azure CLI installation steps](/cli/azure/install-azure-cli-windows).
30+
- Azure CLI. Follow [the Azure CLI installation steps](/cli/azure/install-azure-cli).
3131

3232
## Step 1: Set up local environment
3333

@@ -103,7 +103,7 @@ Configure the file:
103103
...
104104
```
105105

106-
1. If you'd like to enable CAPTCHA in your developer portal, see [Enable CAPTCHA](#enable-captcha).
106+
1. If you'd like to enable CAPTCHA in your developer portal, set `"useHipCaptcha": true`. Make sure to [configure CORS settings for developer portal backend](#configure-cors-settings-for-developer-portal-backend).
107107

108108
### config.publish.json file
109109

@@ -122,7 +122,7 @@ Configure the file:
122122

123123
1. Copy and paste the `managementApiUrl` and `managementApiAccessToken` values from the previous configuration file.
124124

125-
1. If you'd like to enable CAPTCHA in your developer portal, see [Enable CAPTCHA](#enable-captcha).
125+
1. If you'd like to enable CAPTCHA in your developer portal, set `"useHipCaptcha": true`. Make sure to [configure CORS settings for developer portal backend](#configure-cors-settings-for-developer-portal-backend).
126126

127127
### config.runtime.json file
128128

@@ -163,9 +163,9 @@ Configure the **Static website** feature in your storage account by providing ro
163163

164164
1. Select **Save**.
165165

166-
### Configure the CORS settings
166+
### Configure CORS settings for storage account
167167

168-
Configure the Cross-Origin Resource Sharing (CORS) settings:
168+
Configure the Cross-Origin Resource Sharing (CORS) settings for the storage account:
169169

170170
1. Go to your storage account in the Azure portal and select **CORS** from the menu on the left.
171171

@@ -181,6 +181,22 @@ Configure the Cross-Origin Resource Sharing (CORS) settings:
181181

182182
1. Select **Save**.
183183

184+
### Configure CORS settings for developer portal backend
185+
186+
Configure CORS settings for the developer portal backend to allow requests originating through your self-hosted developer portal. The self-hosted developer portal relies on the developer portal's backend endpoint (set in `backendUrl` in the portal configuration files) to enable several features, including:
187+
188+
* CAPTCHA verification
189+
* [OAuth 2.0 authorization](api-management-howto-oauth2.md) in the test console
190+
* [Delegation](api-management-howto-setup-delegation.md) of user authentication and product subscription
191+
192+
To add CORS settings:
193+
194+
1. Go to your API Management instance in the Azure portal, and select **Developer portal** > **Portal settings** from the menu on the left.
195+
1. On the **Self-hosted portal configuration** tab, add one or more **Origin** domain values. For example:
196+
* The domain where the self-hosted portal is hosted, such as `https://www.contoso.com`
197+
* `localhost` for local development (if applicable), such as `http://localhost:8080` or `https://localhost:8080`
198+
1. Select **Save**.
199+
184200
## Step 3: Run the portal
185201

186202
Now you can build and run a local portal instance in the development mode. In development mode, all the optimizations are turned off and the source maps are turned on.
@@ -404,37 +420,6 @@ The conversion process is almost identical to setting up a generic self-hosted p
404420
> [!TIP]
405421
> We recommend using a separate storage account in the `config.publish.json` file. This approach gives you more control and simplifies the management of the hosting service of your portal.
406422

407-
## Enable CAPTCHA
408-
409-
When setting up the self-hosted portal, you may have disabled CAPTCHA through the `useHipCaptcha` setting. Communication with CAPTCHA happens through an endpoint, which lets Cross-Origin Resource Sharing (CORS) happen for only the managed developer portal hostname. If your developer portal is self-hosted, it uses a different hostname and CAPTCHA won't allow the communication.
410-
411-
### Update the JSON config files
412-
413-
To enable the CAPTCHA in your self-hosted portal:
414-
415-
1. Assign a custom domain (for example, `api.contoso.com`) to the **Developer portal** endpoint of your API Management service.
416-
417-
This domain applies to the managed version of your portal and the CAPTCHA endpoint. For steps, see [Configure a custom domain name for your Azure API Management instance](configure-custom-domain.md).
418-
419-
1. Go to the `src` folder in the [local environment](#step-1-set-up-local-environment) for your self-hosted portal.
420-
421-
1. Update the configuration `json` files:
422-
423-
| File | New value | Note |
424-
| ---- | --------- | ---- |
425-
| `config.design.json`| `"backendUrl": "https://<custom-domain>"` | Replace `<custom-domain>` with the custom domain you set up in the first step. |
426-
| | `"useHipCaptcha": true` | Change the value to `true` |
427-
| `config.publish.json`| `"backendUrl": "https://<custom-domain>"` | Replace `<custom-domain>` with the custom domain you set up in the first step. |
428-
| | `"useHipCaptcha": true` | Change the value to `true` |
429-
| `config.runtime.json` | `"backendUrl": "https://<custom-domain>"` | Replace `<custom-domain>` with the custom domain you set up in the first step. |
430-
431-
1. [Publish](#step-5-publish-locally) the portal.
432-
433-
1. [Upload](#step-6-upload-static-files-to-a-blob) and host the newly published portal.
434-
435-
1. Expose the self-hosted portal through a custom domain.
436-
437-
The portal domain's first and second levels need to match the domain set up in the first step. For example, `portal.contoso.com`. The exact steps depend on your hosting platform of choice. If you used an Azure storage account, you can refer to [Map a custom domain to an Azure Blob Storage endpoint](../storage/blobs/storage-custom-domain-name.md) for instructions.
438423

439424
## Next steps
440425

0 commit comments

Comments
 (0)