Skip to content

Commit

Permalink
1.0.5.0 - Require HTTPS
Browse files Browse the repository at this point in the history
  • Loading branch information
Lurchicus committed Apr 23, 2021
1 parent 4e79675 commit 5463134
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DiceAPI/DiceAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.4.0</Version>
<Version>1.0.5.0</Version>
<Authors>Dan Rhea</Authors>
<Product>DiceAPI</Product>
<Description>A dice rolling API (WIP) - Licensed under GNU GPL3</Description>
Expand Down
25 changes: 22 additions & 3 deletions DiceAPI/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -9,8 +10,11 @@ namespace DiceAPI
{
public class Startup
{
public Startup(IConfiguration configuration)
private readonly IWebHostEnvironment _env;

public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
_env = env;
Configuration = configuration;
}

Expand All @@ -24,6 +28,23 @@ public void ConfigureServices(IServiceCollection services)
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "DiceAPI", Version = "v1" });
});

if (_env.IsDevelopment())
{
services.AddHttpsRedirection(options =>
{
options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect;
options.HttpsPort = 5001;
});
}
else
{
services.AddHttpsRedirection(options =>
{
options.RedirectStatusCode = StatusCodes.Status308PermanentRedirect;
options.HttpsPort = 443;
});
}
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand All @@ -37,9 +58,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
Expand Down

0 comments on commit 5463134

Please sign in to comment.