From 67f1c838aea4a15786e67660b706407adb164dcd Mon Sep 17 00:00:00 2001 From: Darkstack <1835601+darkstack@users.noreply.github.com> Date: Sat, 6 Oct 2018 02:55:29 +0200 Subject: [PATCH] Config Linux --- LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj | 6 ++++++ LaDOSE.Src/LaDOSE.Api/Program.cs | 17 +++++++++-------- LaDOSE.Src/LaDOSE.Api/Startup.cs | 6 +++++- LaDOSE.Src/LaDOSE.Api/appsettings.json | 8 +++++++- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj index 343ba8b..bb27108 100644 --- a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj +++ b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj @@ -17,6 +17,12 @@ + + + Always + + + Always diff --git a/LaDOSE.Src/LaDOSE.Api/Program.cs b/LaDOSE.Src/LaDOSE.Api/Program.cs index 5a2dcad..b28033f 100644 --- a/LaDOSE.Src/LaDOSE.Api/Program.cs +++ b/LaDOSE.Src/LaDOSE.Api/Program.cs @@ -22,21 +22,22 @@ namespace LaDOSE.Api config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appSettings.json", optional: true, reloadOnChange: true) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); - var certificateSettings = config.GetSection("certificateSettings"); - string certificateFileName = certificateSettings.GetValue("filename"); - string certificatePassword = certificateSettings.GetValue("password"); + //var certificateSettings = config.GetSection("CertificateSettings"); + //string certificateFileName = certificateSettings.GetValue("filename"); + //string certificatePassword = certificateSettings.GetValue("password"); - X509Certificate2 certificate = new X509Certificate2(certificateFileName, certificatePassword); - CreateWebHostBuilder(certificate,args).Build().Run(); + //X509Certificate2 certificate = new X509Certificate2(certificateFileName, certificatePassword); + CreateWebHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(X509Certificate2 certificate, string[] args) + public static IWebHostBuilder CreateWebHostBuilder(string[] args) { return WebHost.CreateDefaultBuilder(args) + .UseContentRoot(Directory.GetCurrentDirectory()) .UseConfiguration(config) - .UseKestrel(options => options.Listen(IPAddress.Loopback,int.Parse(config["Port"]),config=> config.UseHttps(certificate))) + .UseKestrel(options => options.Listen(IPAddress.Loopback,int.Parse(config["Port"]))) .UseStartup(); } } diff --git a/LaDOSE.Src/LaDOSE.Api/Startup.cs b/LaDOSE.Src/LaDOSE.Api/Startup.cs index 1f08ad9..84cf050 100644 --- a/LaDOSE.Src/LaDOSE.Api/Startup.cs +++ b/LaDOSE.Src/LaDOSE.Api/Startup.cs @@ -35,10 +35,14 @@ namespace LaDOSE.Api // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + var MySqlServer = this.Configuration["MySql:Server"]; + var MySqlDatabase = this.Configuration["MySql:Database"]; + var MySqlUser = this.Configuration["MySql:User"]; + var MySqlPassword = this.Configuration["MySql:Password"]; services.AddCors(); services.AddMvc(); services.AddDbContextPool( // replace "YourDbContext" with the class name of your DbContext - options => options.UseMySql("Server=localhost;Database=ladose;User=root;Password=;", // replace with your Connection String + options => options.UseMySql($"Server={MySqlServer};Database={MySqlDatabase};{MySqlUser}=root;Password={MySqlPassword};", // replace with your Connection String mysqlOptions => { mysqlOptions.ServerVersion(new Version(10, 1, 16), ServerType.MariaDb); // replace with your Server Version and Type diff --git a/LaDOSE.Src/LaDOSE.Api/appsettings.json b/LaDOSE.Src/LaDOSE.Api/appsettings.json index d3c07c5..ca6066c 100644 --- a/LaDOSE.Src/LaDOSE.Api/appsettings.json +++ b/LaDOSE.Src/LaDOSE.Api/appsettings.json @@ -4,10 +4,16 @@ "Default": "Warning" } }, - "certificateSettings": { + "CertificateSettings": { "fileName": "localhost.pfx", "password": "YourSecurePassword" }, + "MySql": { + "Server": "host", + "Database": "database", + "User": "User", + "Password": "Password" + }, "AllowedHosts": "*", "Port": 5000, "JWTTokenSecret": "here goes the custom Secret key for authnetication"