backend to fix
This commit is contained in:
+32
-3
@@ -3,9 +3,38 @@ using Infrastructure;
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Https;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Specify the paths to your certificate and key files
|
||||
var certPath = Path.Combine(Directory.GetCurrentDirectory(), "cert.pem");
|
||||
var keyPath = Path.Combine(Directory.GetCurrentDirectory(), "key.pem");
|
||||
|
||||
// Load the certificate and key
|
||||
var certificate = new X509Certificate2(certPath);
|
||||
var privateKeyText = File.ReadAllText(keyPath);
|
||||
var rsaPrivateKey = RSA.Create();
|
||||
rsaPrivateKey.ImportFromPem(privateKeyText.ToCharArray());
|
||||
|
||||
// Combine the certificate and private key into one X509Certificate2 object
|
||||
var certificateWithKey = certificate.CopyWithPrivateKey(rsaPrivateKey);
|
||||
|
||||
builder.WebHost.ConfigureKestrel(serverOptions =>
|
||||
{
|
||||
serverOptions.ListenAnyIP(5000); // Set HTTP port
|
||||
serverOptions.ListenAnyIP(5001, listenOptions => // Set HTTPS port
|
||||
{
|
||||
// Apply the certificate with the private key to HTTPS
|
||||
listenOptions.UseHttps(new HttpsConnectionAdapterOptions
|
||||
{
|
||||
ServerCertificate = certificateWithKey,
|
||||
ClientCertificateMode = ClientCertificateMode.NoCertificate
|
||||
});
|
||||
});
|
||||
});;
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll",
|
||||
@@ -57,13 +86,13 @@ if (app.Environment.IsDevelopment())
|
||||
}
|
||||
|
||||
app.UseCors("AllowAll");
|
||||
//app.UseHttpsRedirection();
|
||||
app.UseHttpsRedirection();
|
||||
app.MapControllers();
|
||||
|
||||
// Middlewares
|
||||
app.UseMiddleware<ApiKeyMiddleware>();
|
||||
app.UseMiddleware<BodyCheckMiddleware>();
|
||||
//app.UseMiddleware<JwtMiddleware>();
|
||||
app.UseMiddleware<JwtMiddleware>();
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
@@ -78,4 +107,4 @@ static void EnsureDatabaseCreated(HealthcareManagerDatabase dbContext)
|
||||
{
|
||||
// Checking for pending migrations is more efficient than applying migrations unconditionally
|
||||
if (dbContext.Database.GetPendingMigrations().Any()) dbContext.Database.Migrate();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user