This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
57 lines (47 loc) · 1.89 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Relay.Services;
namespace Relay
{
internal static class Program
{
public static void Main(string[] args) => CreateWebHostBuilder(args).Build().Run();
// ReSharper disable once MemberCanBePrivate.Global
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
if (!Directory.Exists("Config"))
Directory.CreateDirectory("Config");
if (!File.Exists("Config/Relay.json"))
File.Copy("Relay.json", "Config/Relay.json", false);
var config = new ConfigurationBuilder()
.AddJsonFile("Config/Relay.json", true)
.AddEnvironmentVariables("relay_")
.Build();
var ports = new List<int>{5004};
// Don't enable port 80 in dev mode, requires root on unix
var devMode = Environment
.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")?
.Equals(EnvironmentName.Development) ?? false;
if(!devMode) ports.Add(80);
return new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseStartup<Server>()
.UseUrls(ports.Select(p => $"http://0.0.0.0:{p}").ToArray())
.ConfigureLogging((_, logging) =>
{
logging
.ClearProviders()
.SetMinimumLevel(LogLevel.Warning)
.AddConsole()
.AddFilter("Relay", LogLevel.Information)
.AddFilter("Microsoft.AspNetCore.Hosting", LogLevel.Information);
});
}
}
}