Skip to content

Commit c68526c

Browse files
committed
Adding homepage
1 parent d3fb165 commit c68526c

File tree

9 files changed

+355
-9
lines changed

9 files changed

+355
-9
lines changed
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Net;
56
using System.Net.Http;
7+
using System.Net.Http.Formatting;
8+
using System.Text;
69
using System.Web.Http;
10+
using Microsoft.Azure.WebJobs.Script.WebHost.Properties;
711

812
namespace Microsoft.Azure.WebJobs.Script.WebHost.Controllers
913
{
1014
public class HomeController : ApiController
1115
{
16+
public static bool IsHomepageDisabled
17+
{
18+
get
19+
{
20+
return string.Equals(Environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebJobsDisableHomepage),
21+
bool.TrueString, StringComparison.OrdinalIgnoreCase);
22+
}
23+
}
24+
1225
public HttpResponseMessage Get()
1326
{
14-
// TODO: Eventually we'll want to consider returning a content
15-
// page
16-
return new HttpResponseMessage(HttpStatusCode.NoContent);
27+
return IsHomepageDisabled
28+
? new HttpResponseMessage(HttpStatusCode.NoContent)
29+
: new HttpResponseMessage(HttpStatusCode.OK)
30+
{
31+
Content = new StringContent(Resources.Homepage, Encoding.UTF8, "text/html")
32+
};
1733
}
1834
}
1935
}

src/WebJobs.Script.WebHost/GlobalSuppressions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@
7171
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Models.ApiModel.#Links")]
7272
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Models.ApiModelUtility.#.cctor()")]
7373
[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.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", 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.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.SecretManager.#.ctor(System.String,Microsoft.Azure.WebJobs.Script.WebHost.IKeyValueConverterFactory,System.Boolean)")]
75+
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Controllers.HomeController.#IsHomePageDisabled")]
76+
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Azure.WebJobs.Script.WebHost.Controllers.HomeController.#Get()")]

src/WebJobs.Script.WebHost/Home.html

Lines changed: 293 additions & 0 deletions
Large diffs are not rendered by default.

src/WebJobs.Script.WebHost/Properties/Resources.Designer.cs

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WebJobs.Script.WebHost/Properties/Resources.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@
181181
]
182182
}</value>
183183
</data>
184+
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
185+
<data name="Homepage" type="System.Resources.ResXFileRef, System.Windows.Forms">
186+
<value>..\Home.html;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
187+
</data>
184188
<data name="HostSecretsSchemaV0" xml:space="preserve">
185189
<value>{
186190
"type": "object",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,10 @@
379379
<EmbeddedResource Include="Properties\Resources.resx">
380380
<Generator>ResXFileCodeGenerator</Generator>
381381
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
382+
<SubType>Designer</SubType>
382383
</EmbeddedResource>
383384
<EmbeddedResource Include="Resources\Functions\Test-FSharp\run.fsx" />
385+
<EmbeddedResource Include="Home.html" />
384386
<Content Include="Web.config" />
385387
</ItemGroup>
386388
<ItemGroup>

src/WebJobs.Script/EnvironmentSettingNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ public static class EnvironmentSettingNames
1616
public const string AzureWebsiteHomePath = "HOME";
1717
public const string AzureWebJobsScriptRoot = "AzureWebJobsScriptRoot";
1818
public const string CompilationReleaseMode = "AzureWebJobsDotNetReleaseCompilation";
19+
public const string AzureWebJobsDisableHomepage = "AzureWebJobsDisableHomepage";
1920
}
2021
}

test/WebJobs.Script.Tests/Controllers/ControllerScenarioTestFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private bool IsHostRunning()
6161
{
6262
using (HttpResponseMessage response = this.HttpClient.SendAsync(request).Result)
6363
{
64-
return response.StatusCode == HttpStatusCode.NoContent;
64+
return response.StatusCode == HttpStatusCode.NoContent || response.StatusCode == HttpStatusCode.OK;
6565
}
6666
}
6767
}

test/WebJobs.Script.Tests/SamplesEndToEndTests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public async Task EventHubTrigger()
5858
}
5959

6060
string connectionString = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender");
61-
ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(connectionString);
61+
ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(connectionString);
6262
EventHubClient eventHubClient;
6363
if (!string.IsNullOrWhiteSpace(builder.EntityPath))
6464
{
@@ -183,7 +183,19 @@ public async Task Home_Get_Succeeds()
183183
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, string.Empty);
184184

185185
HttpResponseMessage response = await this._fixture.HttpClient.SendAsync(request);
186-
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
186+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
187+
}
188+
189+
[Fact]
190+
public async Task Home_Get_WithHomepageDisabled_Succeeds()
191+
{
192+
using (new TestScopedEnvironmentVariables(EnvironmentSettingNames.AzureWebJobsDisableHomepage, bool.TrueString))
193+
{
194+
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, string.Empty);
195+
196+
HttpResponseMessage response = await this._fixture.HttpClient.SendAsync(request);
197+
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
198+
}
187199
}
188200

189201
[Fact]
@@ -288,7 +300,7 @@ public async Task HttpTrigger_CustomRoute_Get_ReturnsExpectedResponse()
288300
json = await response.Content.ReadAsStringAsync();
289301
JArray products = JArray.Parse(json);
290302
Assert.Equal(2, products.Count);
291-
303+
292304
// test a constraint violation (invalid id)
293305
uri = $"api/node/products/electronics/notaguid?code={functionKey}";
294306
request = new HttpRequestMessage(HttpMethod.Get, uri);
@@ -920,7 +932,7 @@ private bool IsHostRunning()
920932
{
921933
using (HttpResponseMessage response = this.HttpClient.SendAsync(request).Result)
922934
{
923-
return response.StatusCode == HttpStatusCode.NoContent;
935+
return response.StatusCode == HttpStatusCode.NoContent || response.StatusCode == HttpStatusCode.OK;
924936
}
925937
}
926938
}

0 commit comments

Comments
 (0)