Skip to content

Commit

Permalink
🔧 feat: adding support for a reverse proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigolira authored and larismourullo committed Nov 1, 2020
1 parent 5fdee4f commit 083cf9c
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/DevTranslate.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DevTranslate.Api.Context;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -12,28 +13,49 @@ namespace DevTranslate.Api
{
public class Startup
{
public Startup(IConfiguration configuration)
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
{
Configuration = configuration;
Environment = environment;
}

public IConfiguration Configuration { get; }

public IWebHostEnvironment Environment { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();



services.AddDbContext<DevTranslateContext>(options =>
{
options.UseMySql(Configuration.GetConnectionString("DevTranslateConnectionString"), mySqlOptions =>
{
mySqlOptions.ServerVersion(new Version(5, 7), ServerType.MySql);
if (Environment.IsDevelopment())
{
mySqlOptions.ServerVersion(new Version(5, 7), ServerType.MySql);
}
if (Environment.IsProduction())
{
mySqlOptions.ServerVersion(new Version(8, 0), ServerType.MySql);
}
});
});
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsProduction())
{
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
}

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand Down

0 comments on commit 083cf9c

Please sign in to comment.