Skip to content

Commit

Permalink
Support configurable URLs (#525)
Browse files Browse the repository at this point in the history
Fixes #485 and #289
  • Loading branch information
SeppPenner authored Jun 13, 2020
1 parent 1954e94 commit 63d7633
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/BaGet.Core/Configuration/BaGetOptions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace BaGet.Core
{
public class BaGetOptions
{
/// <summary>
/// <summary>
/// The API Key required to authenticate package
/// operations. If empty, package operations do not require authentication.
/// </summary>
Expand Down Expand Up @@ -34,10 +33,16 @@ public class BaGetOptions
public bool AllowPackageOverwrites { get; set; } = false;

/// <summary>
/// If true, disables package pushing, deleting, and relisting.
/// If true, disables package pushing, deleting, and re-listing.
/// </summary>
public bool IsReadOnlyMode { get; set; } = false;

/// <summary>
/// The URLs the BaGet server will use.
/// 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>.
/// </summary>
public string Urls { get; set; }

[Required]
public DatabaseOptions Database { get; set; }

Expand Down
17 changes: 15 additions & 2 deletions src/BaGet/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.IO;
using System.Threading.Tasks;
using BaGet.Core;
using BaGet.Hosting;
using McMaster.Extensions.CommandLineUtils;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

Expand All @@ -28,7 +30,6 @@ public static async Task Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
var importer = host.Services.GetRequiredService<DownloadsImporter>();

await importer.ImportAsync(cancellationToken);
});
});
Expand All @@ -37,7 +38,6 @@ public static async Task Main(string[] args)
app.OnExecuteAsync(async cancellationToken =>
{
var host = CreateWebHostBuilder(args).Build();

await host.RunMigrationsAsync(cancellationToken);
await host.RunAsync(cancellationToken);
});
Expand All @@ -56,6 +56,19 @@ public static IHostBuilder CreateWebHostBuilder(string[] args) =>
options.Limits.MaxRequestBodySize = null;
});

var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true)
.AddCommandLine(args)
.Build();

var urls = config["Urls"];

if (!string.IsNullOrWhiteSpace(urls))
{
web.UseUrls(urls);
}

web.UseStartup<Startup>();
});

Expand Down
1 change: 1 addition & 0 deletions src/BaGet/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"ApiKey": "",
"Urls": "http://*:5000",
"PackageDeletionBehavior": "Unlist",
"AllowPackageOverwrites": false,

Expand Down

0 comments on commit 63d7633

Please sign in to comment.