DocSpace-buildtools/products/ASC.Calendar/Server/Program.cs

90 lines
3.6 KiB
C#
Raw Normal View History

2021-09-23 17:58:39 +00:00
using System;
2020-02-12 07:58:31 +00:00
using System.Collections.Generic;
using System.IO;
2021-09-23 17:58:39 +00:00
using System.Runtime.InteropServices;
2021-08-08 13:19:54 +00:00
using System.Threading.Tasks;
using ASC.Api.Core;
2021-09-23 17:58:39 +00:00
using ASC.Common.Utils;
2021-08-08 13:19:54 +00:00
2021-04-20 07:55:52 +00:00
using Autofac.Extensions.DependencyInjection;
2020-02-12 07:58:31 +00:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace ASC.Calendar
{
public class Program
{
public static async Task Main(string[] args)
2020-02-12 07:58:31 +00:00
{
var host = CreateHostBuilder(args).Build();
await host.RunAsync();
2020-02-12 07:58:31 +00:00
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
2021-09-23 17:58:39 +00:00
.UseSystemd()
.UseWindowsService()
2021-04-20 07:55:52 +00:00
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
2020-02-12 07:58:31 +00:00
.ConfigureWebHostDefaults(webBuilder =>
2021-09-23 17:58:39 +00:00
{
var builder = webBuilder.UseStartup<Startup>();
builder.ConfigureKestrel((hostingContext, serverOptions) =>
{
serverOptions.Limits.MaxRequestBodySize = 100 * 1024 * 1024;
serverOptions.Limits.MaxRequestBufferSize = 100 * 1024 * 1024;
serverOptions.Limits.MinRequestBodyDataRate = null;
serverOptions.Limits.MinResponseDataRate = null;
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
if (!kestrelConfig.Exists()) return;
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (!String.IsNullOrWhiteSpace(unixSocket))
{
unixSocket = String.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
serverOptions.ListenUnixSocket(unixSocket);
}
}
});
2020-02-12 07:58:31 +00:00
})
.ConfigureAppConfiguration((hostingContext, config) =>
{
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
{
2021-09-23 17:58:39 +00:00
path = Path.GetFullPath(CrossPlatform.PathCombine(hostingContext.HostingEnvironment.ContentRootPath, path));
2020-02-12 07:58:31 +00:00
}
config.SetBasePath(path);
config
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
.AddJsonFile("storage.json")
.AddJsonFile("kafka.json")
.AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
.AddJsonFile("rabbitmq.json")
.AddJsonFile($"rabbitmq.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
.AddJsonFile("redis.json")
.AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
2021-04-21 18:47:27 +00:00
.AddEnvironmentVariables()
2021-09-23 17:58:39 +00:00
.AddCommandLine(args)
.AddInMemoryCollection(new Dictionary<string, string>
{
{"pathToConf", path}
});
2021-08-08 13:19:54 +00:00
})
.ConfigureNLogLogging();
2020-02-12 07:58:31 +00:00
}
}