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);
|
||||
// });
|
||||
|
||||
optionsBuilder.UseSqlite("Filename=Sledgemapper.db").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
optionsBuilder.UseSqlite("Filename=db/sledgemapper.db").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
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<Campaign>().HasMany(e => e.InvitedUsers).WithMany(e => e.Campaigns);
|
||||
|
||||
modelBuilder.Entity<User>() //Use your application user class here
|
||||
.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
|
||||
// modelBuilder.Entity<MapLog>().ToTable("MapLog", "dbo");
|
||||
|
|
|
@ -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"));
|
||||
|
||||
|
@ -49,29 +78,30 @@ namespace Sledgemapper.Api
|
|||
|
||||
// within this section we are configuring the authentication and setting the default scheme
|
||||
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
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key), // Add the secret key to our Jwt encryption
|
||||
ValidateIssuer = false,
|
||||
ValidateAudience = false,
|
||||
RequireExpirationTime = false,
|
||||
ValidateLifetime = true
|
||||
};
|
||||
});
|
||||
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
|
||||
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)
|
||||
.AddEntityFrameworkStores<SledgemapperDbContext>();
|
||||
.AddEntityFrameworkStores<SledgemapperDbContext>();
|
||||
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
|
@ -87,56 +117,20 @@ namespace Sledgemapper.Api
|
|||
Name = "Authorization",
|
||||
Type = SecuritySchemeType.ApiKey
|
||||
});
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement {
|
||||
{ new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
Array.Empty<string>()
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
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": {
|
||||
"WebApiDatabase": "Data Source=db/LocalDatabase.db"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"WebApiDatabase": "Data Source=db/sledgemapper.db"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"ConnectionStrings": {
|
||||
"WebApiDatabase": "Data Source=db/LocalDatabase.db"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"WebApiDatabase": "Data Source=db/sledgemapper.db"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,11 +35,12 @@ 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();
|
||||
CheckLogin();
|
||||
|
||||
_retryPolicy = Policy
|
||||
.Handle<ApiException>(ex => ex.StatusCode == HttpStatusCode.RequestTimeout)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue