tgstation-server 5.12.7
The /tg/station 13 server suite
Loading...
Searching...
No Matches
ServerPortProivder.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3
4using Microsoft.Extensions.Configuration;
5using Microsoft.Extensions.Logging;
6using Microsoft.Extensions.Options;
7
9
11{
14 {
17
22
30 IOptions<GeneralConfiguration> generalConfigurationOptions,
31 IConfiguration configuration,
32 ILogger<ServerPortProivder> logger)
33 {
34 generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
35 ArgumentNullException.ThrowIfNull(configuration);
36
37 var httpEndpoint = configuration
38 .GetSection("Kestrel")
39 .GetSection("EndPoints")
40 .GetSection("Http")
41 .GetSection("Url")
42 .Value;
43
44 if (generalConfiguration.ApiPort == default && httpEndpoint == null)
45 throw new InvalidOperationException("Missing required configuration option General:ApiPort!");
46
47 if (generalConfiguration.ApiPort != default)
48 return;
49
50 logger.LogWarning("The \"Kestrel\" configuration section is deprecated! Please set your API port using the \"General:ApiPort\" configuration option!");
51
52 var splits = httpEndpoint.Split(":", StringSplitOptions.RemoveEmptyEntries);
53 var portString = splits.Last();
54 portString = portString.TrimEnd('/');
55
56 if (!UInt16.TryParse(portString, out var result))
57 throw new InvalidOperationException($"Failed to parse HTTP EndPoint port: {httpEndpoint}");
58
59 generalConfiguration.ApiPort = result;
60 }
61 }
62}
readonly GeneralConfiguration generalConfiguration
The GeneralConfiguration for the ServerPortProivder.
ushort HttpApiPort
The port the server listens on.
ServerPortProivder(IOptions< GeneralConfiguration > generalConfigurationOptions, IConfiguration configuration, ILogger< ServerPortProivder > logger)
Initializes a new instance of the ServerPortProivder class.
Provides access to the server's HttpApiPort.