db issues for prod
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Michele Scandura 2021-09-23 14:34:33 +01:00
parent 5b7ad4f2ff
commit 6c167ed4de
6 changed files with 105 additions and 110 deletions

View file

@ -37,7 +37,7 @@ namespace Sledgemapper.Api.Infrastructure.Data
// options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
// });
optionsBuilder.UseSqlite("Filename=Sledgemapper.db").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
optionsBuilder.UseSqlite("Filename=db/sledgemapper.db").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
base.OnConfiguring(optionsBuilder);
}

View file

@ -1,30 +1,57 @@
using System;
using System.Text;
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Sledgemapper.Api.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using MediatR;
using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using System.Text;
using Sledgemapper.Api.Hubs;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Sledgemapper.Api.Core.Entities;
using Sledgemapper.Api.Hubs;
using Sledgemapper.Api.Infrastructure.Data;
namespace Sledgemapper.Api
{
public class Startup
{
private readonly IWebHostEnvironment _env;
public IConfiguration Configuration { get; }
public Startup(IWebHostEnvironment env, IConfiguration configuration)
{
Configuration = configuration;
_env = env;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SledgemapperDbContext dataContext)
{
// 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"); });
dataContext.Database.Migrate();
app.UseRouting();
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
app.UseEndpoints(endpoints => { endpoints.MapHub<SledgemapperHub>("/sledgemapperhub"); });
}
// This method gets called by the runtime. Use this method to add services to the container.
@ -34,14 +61,16 @@ namespace Sledgemapper.Api
services.AddControllers().AddNewtonsoftJson(o =>
{
o.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
}); ;
});
services.AddSignalR();
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
services.AddMediatR(typeof(Startup));
services.AddDbContext<SledgemapperDbContext>(options => { options.UseSqlite("Data Source=db/sledgemapper.db"); options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); });
services.AddDbContext<SledgemapperDbContext>(options =>
{
options.UseSqlite("Data Source=db/sledgemapper.db");
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});
services.Configure<JwtConfig>(Configuration.GetSection("JwtConfig"));
@ -61,7 +90,8 @@ namespace Sledgemapper.Api
jwt.SaveToken = true;
jwt.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true, // this will validate the 3rd part of the jwt token using the secret that we added in the appsettings and verify we have generated the jwt token
ValidateIssuerSigningKey =
true, // this will validate the 3rd part of the jwt token using the secret that we added in the appsettings and verify we have generated the jwt token
IssuerSigningKey = new SymmetricSecurityKey(key), // Add the secret key to our Jwt encryption
ValidateIssuer = false,
ValidateAudience = false,
@ -87,8 +117,10 @@ namespace Sledgemapper.Api
Name = "Authorization",
Type = SecuritySchemeType.ApiKey
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement {
{ new OpenApiSecurityScheme
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
@ -100,44 +132,6 @@ namespace Sledgemapper.Api
}
});
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SledgemapperDbContext dataContext)
{
// 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");
});
dataContext.Database.Migrate();
app.UseRouting();
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<SledgemapperHub>("/sledgemapperhub");
});
}
}
}

View file

@ -1,6 +1,6 @@
{
{
"ConnectionStrings": {
"WebApiDatabase": "Data Source=db/LocalDatabase.db"
"WebApiDatabase": "Data Source=db/sledgemapper.db"
},
"Logging": {
"LogLevel": {

View file

@ -1,6 +1,6 @@
{
{
"ConnectionStrings": {
"WebApiDatabase": "Data Source=db/LocalDatabase.db"
"WebApiDatabase": "Data Source=db/sledgemapper.db"
},
"Logging": {
"LogLevel": {

View file

@ -35,8 +35,9 @@ namespace Sledgemapper
_queue = new ChannelsQueue(Messenger);
#if DEBUG
var baseAddress = "http://localhost:5000";
baseAddress = "http://hub.michelescandura.com:5001";
#else
var baseAddress = "http://hub.michelescandura.com:5000";
var baseAddress = "http://hub.michelescandura.com:5001";
#endif
CheckLogin();

View file

@ -21,7 +21,7 @@ namespace Sledgemapper.UI
_messenger = messenger;
#if DEBUG
TxtEmail.Text = "michele.scandura@outlook.com";
TxtEmail.Text = "michele.scandura@sloutlook.com";
TxtPassword.Text = "slePharland!79";
#endif