Skip to content

Commit 7728897

Browse files
committed
Latest Proxy version is broken when route is to the root of the function app
Azure/Azure-Functions#505
1 parent b3b80ae commit 7728897

File tree

6 files changed

+30
-48
lines changed

6 files changed

+30
-48
lines changed

src/WebJobs.Script.WebHost/App_Start/WebApiConfig.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ public static void Register(HttpConfiguration config, ScriptSettingsManager sett
5858
// Web API routes
5959
config.MapHttpAttributeRoutes();
6060

61-
config.Routes.MapHttpRoute(
62-
name: "Home",
63-
routeTemplate: string.Empty,
64-
defaults: new { controller = "Home" });
65-
6661
config.Routes.MapHttpRoute(
6762
name: "Functions",
6863
routeTemplate: "{*uri}",

src/WebJobs.Script.WebHost/Controllers/FunctionsController.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Net;
77
using System.Net.Http;
8+
using System.Text;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using System.Web.Http;
@@ -13,6 +14,7 @@
1314
using Microsoft.Azure.WebJobs.Extensions.Http;
1415
using Microsoft.Azure.WebJobs.Script.Description;
1516
using Microsoft.Azure.WebJobs.Script.WebHost.Filters;
17+
using Microsoft.Azure.WebJobs.Script.WebHost.Properties;
1618
using Microsoft.Azure.WebJobs.Script.WebHost.WebHooks;
1719

1820
namespace Microsoft.Azure.WebJobs.Script.WebHost.Controllers
@@ -31,15 +33,37 @@ public FunctionsController(WebScriptHostManager scriptHostManager, WebHookReceiv
3133
_webHookReceiverManager = webHookReceiverManager;
3234
}
3335

36+
private static bool IsHomepageDisabled
37+
{
38+
get
39+
{
40+
return string.Equals(Environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebJobsDisableHomepage),
41+
bool.TrueString, StringComparison.OrdinalIgnoreCase);
42+
}
43+
}
44+
3445
public override async Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
3546
{
3647
var request = controllerContext.Request;
3748
var function = _scriptHostManager.GetHttpFunctionOrNull(request);
3849
if (function == null)
3950
{
51+
if (request.RequestUri.AbsolutePath == "/")
52+
{
53+
// if the request is to the root and we can't find any matching FunctionDescriptors which might have been setup by proxies
54+
// then homepage logic will be applied.
55+
return IsHomepageDisabled
56+
? new HttpResponseMessage(HttpStatusCode.NoContent)
57+
: new HttpResponseMessage(HttpStatusCode.OK)
58+
{
59+
Content = new StringContent(Resources.Homepage, Encoding.UTF8, "text/html")
60+
};
61+
}
62+
4063
// request does not map to an HTTP function
4164
return new HttpResponseMessage(HttpStatusCode.NotFound);
4265
}
66+
4367
request.SetProperty(ScriptConstants.AzureFunctionsHttpFunctionKey, function);
4468

4569
var authorizationLevel = await DetermineAuthorizationLevelAsync(request, function, controllerContext.Configuration.DependencyResolver);

src/WebJobs.Script.WebHost/Controllers/HomeController.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/WebJobs.Script.WebHost/GlobalSuppressions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", Scope = "namespace", Target = "WebJobs.Script.WebHost.App_Start")]
1212
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "WebJobs.Script.WebHost.App_Start.AutofacBootstrap.#Initialize(Autofac.ContainerBuilder)")]
13-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "WebJobs.Script.WebHost.Controllers.HomeController.#Get()")]
1413
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1018:MarkAttributesWithAttributeUsage", Scope = "type", Target = "WebJobs.Script.WebHost.Filters.AuthorizationLevelAttribute")]
1514
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "WebJobs.Script.WebHost.WebApiApplication.#Application_Start()")]
1615
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "WebJobs.Script.WebHost.WebApiApplication.#Application_Error(System.Object,System.EventArgs)")]
@@ -28,7 +27,6 @@
2827
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Ms", Scope = "member", Target = "WebJobs.Script.WebHost.Diagnostics.IMetricsEventGenerator.#RaiseMetricsPerFunctionEvent(System.String,System.String,System.Int64,System.Int64,System.Int64,System.Int64)")]
2928
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ms", Scope = "member", Target = "WebJobs.Script.WebHost.Diagnostics.IMetricsEventGenerator.#RaiseMetricsPerFunctionEvent(System.String,System.String,System.Int64,System.Int64,System.Int64,System.Int64)")]
3029
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.AutofacBootstrap.#Initialize(Autofac.ContainerBuilder,Microsoft.Azure.WebJobs.Script.WebHost.WebHostSettings)")]
31-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Controllers.HomeController.#Get()")]
3230
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.IMetricsEventGenerator.#RaiseFunctionsMetricEvent(System.String,System.Int64,System.Int64,System.String)")]
3331
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Ms", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.IMetricsEventGenerator.#RaiseMetricsPerFunctionEvent(System.String,System.String,System.Int64,System.Int64,System.Int64,System.Int64)")]
3432
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ms", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.IMetricsEventGenerator.#RaiseMetricsPerFunctionEvent(System.String,System.String,System.Int64,System.Int64,System.Int64,System.Int64)")]
@@ -71,8 +69,6 @@
7169
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Models.ApiModel.#Links")]
7270
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Models.ApiModelUtility.#.cctor()")]
7371
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.SecretManager.#.ctor(System.String,Microsoft.Azure.WebJobs.Script.WebHost.IKeyValueConverterFactory,System.Boolean)")]
74-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Controllers.HomeController.#IsHomePageDisabled")]
75-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Controllers.HomeController.#Get()")]
7672
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Models.ApiModelUtility.#.cctor()")]
7773
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.WebHostResolver.#GetSecretManager(Microsoft.Azure.WebJobs.Script.Settings.ScriptSettingsManager,System.String)")]
7874
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.WebHostResolver.#GetSecretManager(Microsoft.Azure.WebJobs.Script.Config.ScriptSettingsManager,System.String)")]

src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@
470470
<Compile Include="StandbyManager.cs" />
471471
<Compile Include="Controllers\AdminController.cs" />
472472
<Compile Include="Controllers\FunctionsController.cs" />
473-
<Compile Include="Controllers\HomeController.cs" />
474473
<Compile Include="Controllers\KeysController.cs" />
475474
<Compile Include="Filters\JwtAuthenticationAttribute.cs" />
476475
<Compile Include="Handlers\ExceptionProcessingHandler.cs" />

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,9 +1251,11 @@ internal static void ValidateFunction(FunctionDescriptor function, Dictionary<st
12511251
var httpTrigger = function.GetTriggerAttributeOrNull<HttpTriggerAttribute>();
12521252
if (httpTrigger != null)
12531253
{
1254-
ValidateHttpFunction(function.Name, httpTrigger);
1254+
bool isProxy = function.Metadata != null && function.Metadata.IsProxy;
12551255

1256-
if (function.Metadata != null && !function.Metadata.IsProxy)
1256+
ValidateHttpFunction(function.Name, httpTrigger, isProxy);
1257+
1258+
if (!isProxy)
12571259
{
12581260
// prevent duplicate/conflicting routes for functions
12591261
// proxy routes check is done in the proxy dll itself and proxies do not use routePrefix so should not check conflict with functions
@@ -1270,9 +1272,9 @@ internal static void ValidateFunction(FunctionDescriptor function, Dictionary<st
12701272
}
12711273
}
12721274

1273-
internal static void ValidateHttpFunction(string functionName, HttpTriggerAttribute httpTrigger)
1275+
internal static void ValidateHttpFunction(string functionName, HttpTriggerAttribute httpTrigger, bool isProxy = false)
12741276
{
1275-
if (string.IsNullOrWhiteSpace(httpTrigger.Route))
1277+
if (string.IsNullOrWhiteSpace(httpTrigger.Route) && !isProxy)
12761278
{
12771279
// if no explicit route is provided, default to the function name
12781280
httpTrigger.Route = functionName;

0 commit comments

Comments
 (0)