Skip to content

Commit

Permalink
Allow db generation on prod too
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferenc Hammerl committed Oct 21, 2020
1 parent 8efac11 commit f0494b8
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions ExpenseTracker.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env)

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
if (env.IsDevelopment())
if (env.IsDevelopment() || env.IsProduction()) // TODO: define production datacontext and cors policy
{
services.AddDbContext<ExpenseTrackerContext>(options => options.UseSqlite($"Data Source=expensetracker.db"));
services.AddCors(o => o.AddPolicy("AllowAll", builder => // TODO: Restrict from 'allow all'
Expand All @@ -37,20 +36,15 @@ public void ConfigureServices(IServiceCollection services)
services.AddSwaggerGen();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
if (env.IsDevelopment() || env.IsProduction())
{
app.UseDeveloperExceptionPage();
UpdateDatabase(app);
}

// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();

// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
Expand All @@ -69,7 +63,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
});
}

// For Dev purposes only, for prod you should probably do this from the pipeline
private static void UpdateDatabase(IApplicationBuilder app)
{
using (var serviceScope = app.ApplicationServices
Expand Down

0 comments on commit f0494b8

Please sign in to comment.