Skip to content

Commit 94d1f9a

Browse files
committed
Fix SyncTriggers URI for dedicated linux on app service
1 parent 287a270 commit 94d1f9a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,13 @@ internal static HttpRequestMessage BuildSetTriggersRequest()
284284
protocol = "http";
285285
}
286286

287-
var url = $"{protocol}://{Environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName)}/operations/settriggers";
287+
var hostname = Environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName);
288+
// Linux Dedicated on AppService doesn't have WEBSITE_HOSTNAME
289+
hostname = string.IsNullOrWhiteSpace(hostname)
290+
? $"{Environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteName)}.azurewebsites.net"
291+
: hostname;
292+
293+
var url = $"{protocol}://{hostname}/operations/settriggers";
288294

289295
return new HttpRequestMessage(HttpMethod.Post, url);
290296
}

test/WebJobs.Script.Tests/Managment/FunctionsSyncManagerTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,24 @@ public void Disables_Ssl_If_SkipSslValidation_Enabled(int skipSslValidation, str
214214
}
215215
}
216216

217+
[Theory]
218+
[InlineData(EnvironmentSettingNames.AzureWebsiteName, "sitename", "https://sitename.azurewebsites.net/operations/settriggers")]
219+
[InlineData(EnvironmentSettingNames.AzureWebsiteHostName, "sitename", "https://sitename/operations/settriggers")]
220+
public void Use_Website_Name_If_Website_Hostname_Is_Not_Available(string envKey, string envValue, string expectedSyncTriggersUri)
221+
{
222+
var vars = new Dictionary<string, string>
223+
{
224+
{ envKey, envValue },
225+
};
226+
227+
using (var env = new TestScopedEnvironmentVariable(vars))
228+
{
229+
var httpRequest = FunctionsSyncManager.BuildSetTriggersRequest();
230+
Assert.Equal(expectedSyncTriggersUri, httpRequest.RequestUri.AbsoluteUri);
231+
Assert.Equal(HttpMethod.Post, httpRequest.Method);
232+
}
233+
}
234+
217235
private static HttpClient CreateHttpClient(MockHttpHandler httpHandler)
218236
{
219237
return new HttpClient(httpHandler);

0 commit comments

Comments
 (0)