Skip to content

Commit 63d7633

Browse files
authored
Support configurable URLs (loic-sharma#525)
Fixes loic-sharma#485 and loic-sharma#289
1 parent 1954e94 commit 63d7633

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/BaGet.Core/Configuration/BaGetOptions.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System.Collections.Generic;
21
using System.ComponentModel.DataAnnotations;
32

43
namespace BaGet.Core
54
{
65
public class BaGetOptions
76
{
8-
/// <summary>
7+
/// <summary>
98
/// The API Key required to authenticate package
109
/// operations. If empty, package operations do not require authentication.
1110
/// </summary>
@@ -34,10 +33,16 @@ public class BaGetOptions
3433
public bool AllowPackageOverwrites { get; set; } = false;
3534

3635
/// <summary>
37-
/// If true, disables package pushing, deleting, and relisting.
36+
/// If true, disables package pushing, deleting, and re-listing.
3837
/// </summary>
3938
public bool IsReadOnlyMode { get; set; } = false;
4039

40+
/// <summary>
41+
/// The URLs the BaGet server will use.
42+
/// As per documentation <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host?view=aspnetcore-3.1#server-urls">here (Server URLs)</a>.
43+
/// </summary>
44+
public string Urls { get; set; }
45+
4146
[Required]
4247
public DatabaseOptions Database { get; set; }
4348

src/BaGet/Program.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using System.IO;
12
using System.Threading.Tasks;
23
using BaGet.Core;
34
using BaGet.Hosting;
45
using McMaster.Extensions.CommandLineUtils;
56
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.Extensions.Configuration;
68
using Microsoft.Extensions.DependencyInjection;
79
using Microsoft.Extensions.Hosting;
810

@@ -28,7 +30,6 @@ public static async Task Main(string[] args)
2830
{
2931
var host = CreateHostBuilder(args).Build();
3032
var importer = host.Services.GetRequiredService<DownloadsImporter>();
31-
3233
await importer.ImportAsync(cancellationToken);
3334
});
3435
});
@@ -37,7 +38,6 @@ public static async Task Main(string[] args)
3738
app.OnExecuteAsync(async cancellationToken =>
3839
{
3940
var host = CreateWebHostBuilder(args).Build();
40-
4141
await host.RunMigrationsAsync(cancellationToken);
4242
await host.RunAsync(cancellationToken);
4343
});
@@ -56,6 +56,19 @@ public static IHostBuilder CreateWebHostBuilder(string[] args) =>
5656
options.Limits.MaxRequestBodySize = null;
5757
});
5858

59+
var config = new ConfigurationBuilder()
60+
.SetBasePath(Directory.GetCurrentDirectory())
61+
.AddJsonFile("appsettings.json", optional: true)
62+
.AddCommandLine(args)
63+
.Build();
64+
65+
var urls = config["Urls"];
66+
67+
if (!string.IsNullOrWhiteSpace(urls))
68+
{
69+
web.UseUrls(urls);
70+
}
71+
5972
web.UseStartup<Startup>();
6073
});
6174

src/BaGet/appsettings.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"ApiKey": "",
3+
"Urls": "http://*:5000",
34
"PackageDeletionBehavior": "Unlist",
45
"AllowPackageOverwrites": false,
56

0 commit comments

Comments
 (0)