0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure Functions の http routePrefix を host.json はそのまま環境変数で変更してみた

Posted at

Azure Functions の Http Trigger は、デフォルトで api という routePrefix が付きます。これを、host.json を変更せずに、Azure Functions の環境変数に設定して、routePrefix を変更してみました。

検証用 Azure Functions を用意

bash
prefix=mnrfunc
region=japaneast

az group create \
  --name ${prefix}-rg \
  --location $region

az storage account create \
  --name ${prefix}stor \
  --resource-group ${prefix}-rg \
  --sku Standard_LRS

az functionapp create \
  --name ${prefix} \
  --resource-group ${prefix}-rg \
  --consumption-plan-location $region \
  --runtime dotnet \
  --functions-version 4 \
  --storage-account ${prefix}stor \
  --disable-app-insights \
  --https-only \
  --os-type Linux

func init $prefix --dotnet

cd $prefix

func new --name httpsample --template "HTTP trigger" --authlevel "anonymous"

func azure functionapp publish $prefix

routePrefix 変更前の動作確認

bash
$ curl https://$prefix.azurewebsites.net/api/httpsample

This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.

環境変数に routePrefix を prod に設定

bash
az webapp config appsettings set \
  --name ${prefix} \
  --resource-group ${prefix}-rg \
  --settings AzureFunctionsJobHost__extensions__http__routePrefix=prod

routePrefix 変更後の動作確認

bash
$ curl -I https://$prefix.azurewebsites.net/api/httpsample

HTTP/2 404 
date: Fri, 15 Dec 2023 23:39:44 GMT
server: Kestrel

$ curl https://$prefix.azurewebsites.net/prod/httpsample

This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.

(参考) host.json で routePrefix を設定する場合

host.json
{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    },
    "extensions": {
        "http": {
            "routePrefix": "prod"
        }
    }
}

参考情報

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?