db issues for prod
This commit is contained in:
parent
5b7ad4f2ff
commit
6c167ed4de
6 changed files with 105 additions and 110 deletions
|
@ -37,19 +37,19 @@ namespace Sledgemapper.Api.Infrastructure.Data
|
||||||
// options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
|
// 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);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.Entity<Campaign>().HasOne(e=>e.Owner);
|
modelBuilder.Entity<Campaign>().HasOne(e => e.Owner);
|
||||||
|
|
||||||
modelBuilder.Entity<Campaign>().HasMany(e=>e.InvitedUsers).WithMany(e=>e.Campaigns);
|
|
||||||
|
|
||||||
modelBuilder.Entity<User>() //Use your application user class here
|
modelBuilder.Entity<Campaign>().HasMany(e => e.InvitedUsers).WithMany(e => e.Campaigns);
|
||||||
.ToTable( "Users" ); //Set the table name here
|
|
||||||
|
modelBuilder.Entity<User>() //Use your application user class here
|
||||||
|
.ToTable("Users"); //Set the table name here
|
||||||
|
|
||||||
// // Map table names
|
// // Map table names
|
||||||
// modelBuilder.Entity<MapLog>().ToTable("MapLog", "dbo");
|
// modelBuilder.Entity<MapLog>().ToTable("MapLog", "dbo");
|
||||||
|
|
|
@ -1,30 +1,57 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Sledgemapper.Api.Infrastructure.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using MediatR;
|
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
||||||
using System.Text;
|
|
||||||
using Sledgemapper.Api.Hubs;
|
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Sledgemapper.Api.Core.Entities;
|
using Sledgemapper.Api.Core.Entities;
|
||||||
|
using Sledgemapper.Api.Hubs;
|
||||||
|
using Sledgemapper.Api.Infrastructure.Data;
|
||||||
|
|
||||||
namespace Sledgemapper.Api
|
namespace Sledgemapper.Api
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
private readonly IWebHostEnvironment _env;
|
private readonly IWebHostEnvironment _env;
|
||||||
public IConfiguration Configuration { get; }
|
|
||||||
public Startup(IWebHostEnvironment env, IConfiguration configuration)
|
public Startup(IWebHostEnvironment env, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
_env = env;
|
_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.
|
// 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 =>
|
services.AddControllers().AddNewtonsoftJson(o =>
|
||||||
{
|
{
|
||||||
o.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
o.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||||
}); ;
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
services.AddSignalR();
|
services.AddSignalR();
|
||||||
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||||
services.AddMediatR(typeof(Startup));
|
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"));
|
services.Configure<JwtConfig>(Configuration.GetSection("JwtConfig"));
|
||||||
|
|
||||||
|
@ -49,29 +78,30 @@ namespace Sledgemapper.Api
|
||||||
|
|
||||||
// within this section we are configuring the authentication and setting the default scheme
|
// within this section we are configuring the authentication and setting the default scheme
|
||||||
services.AddAuthentication(options =>
|
services.AddAuthentication(options =>
|
||||||
{
|
|
||||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
||||||
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
||||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
||||||
})
|
|
||||||
.AddJwtBearer(jwt =>
|
|
||||||
{
|
|
||||||
var key = Encoding.ASCII.GetBytes(Configuration["JwtConfig:Secret"]);
|
|
||||||
|
|
||||||
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
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
IssuerSigningKey = new SymmetricSecurityKey(key), // Add the secret key to our Jwt encryption
|
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
ValidateIssuer = false,
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
ValidateAudience = false,
|
})
|
||||||
RequireExpirationTime = false,
|
.AddJwtBearer(jwt =>
|
||||||
ValidateLifetime = true
|
{
|
||||||
};
|
var key = Encoding.ASCII.GetBytes(Configuration["JwtConfig:Secret"]);
|
||||||
});
|
|
||||||
|
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
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(key), // Add the secret key to our Jwt encryption
|
||||||
|
ValidateIssuer = false,
|
||||||
|
ValidateAudience = false,
|
||||||
|
RequireExpirationTime = false,
|
||||||
|
ValidateLifetime = true
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
services.AddDefaultIdentity<User>(options => options.SignIn.RequireConfirmedAccount = false)
|
services.AddDefaultIdentity<User>(options => options.SignIn.RequireConfirmedAccount = false)
|
||||||
.AddEntityFrameworkStores<SledgemapperDbContext>();
|
.AddEntityFrameworkStores<SledgemapperDbContext>();
|
||||||
|
|
||||||
services.AddSwaggerGen(c =>
|
services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
|
@ -87,57 +117,21 @@ namespace Sledgemapper.Api
|
||||||
Name = "Authorization",
|
Name = "Authorization",
|
||||||
Type = SecuritySchemeType.ApiKey
|
Type = SecuritySchemeType.ApiKey
|
||||||
});
|
});
|
||||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement {
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||||
{ new OpenApiSecurityScheme
|
{
|
||||||
{
|
{
|
||||||
Reference = new OpenApiReference
|
new OpenApiSecurityScheme
|
||||||
{
|
{
|
||||||
Type = ReferenceType.SecurityScheme,
|
Reference = new OpenApiReference
|
||||||
Id = "Bearer"
|
{
|
||||||
}
|
Type = ReferenceType.SecurityScheme,
|
||||||
},
|
Id = "Bearer"
|
||||||
Array.Empty<string>()
|
}
|
||||||
|
},
|
||||||
|
Array.Empty<string>()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"WebApiDatabase": "Data Source=db/LocalDatabase.db"
|
"WebApiDatabase": "Data Source=db/sledgemapper.db"
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Debug",
|
"Default": "Debug",
|
||||||
"System": "Information",
|
"System": "Information",
|
||||||
"Microsoft": "Information"
|
"Microsoft": "Information"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"WebApiDatabase": "Data Source=db/LocalDatabase.db"
|
"WebApiDatabase": "Data Source=db/sledgemapper.db"
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Debug",
|
"Default": "Debug",
|
||||||
"System": "Information",
|
"System": "Information",
|
||||||
"Microsoft": "Information"
|
"Microsoft": "Information"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,12 @@ namespace Sledgemapper
|
||||||
_queue = new ChannelsQueue(Messenger);
|
_queue = new ChannelsQueue(Messenger);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
var baseAddress = "http://localhost:5000";
|
var baseAddress = "http://localhost:5000";
|
||||||
|
baseAddress = "http://hub.michelescandura.com:5001";
|
||||||
#else
|
#else
|
||||||
var baseAddress = "http://hub.michelescandura.com:5000";
|
var baseAddress = "http://hub.michelescandura.com:5001";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CheckLogin();
|
CheckLogin();
|
||||||
|
|
||||||
_retryPolicy = Policy
|
_retryPolicy = Policy
|
||||||
.Handle<ApiException>(ex => ex.StatusCode == HttpStatusCode.RequestTimeout)
|
.Handle<ApiException>(ex => ex.StatusCode == HttpStatusCode.RequestTimeout)
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace Sledgemapper.UI
|
||||||
_messenger = messenger;
|
_messenger = messenger;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
TxtEmail.Text = "michele.scandura@outlook.com";
|
TxtEmail.Text = "michele.scandura@sloutlook.com";
|
||||||
TxtPassword.Text = "slePharland!79";
|
TxtPassword.Text = "slePharland!79";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue