Add base url as a startup argument

#2153
pull/2161/head
Jamie Rees 7 years ago
parent 7f12ab5e14
commit 7a7b00ab25

@ -17,5 +17,6 @@ namespace Ombi.Store.Entities
TheMovieDb = 4,
StoragePath = 5,
Notification = 6,
BaseUrl=7,
}
}

@ -23,11 +23,13 @@ namespace Ombi
var host = string.Empty;
var storagePath = string.Empty;
var baseUrl = string.Empty;
var result = Parser.Default.ParseArguments<Options>(args)
.WithParsed(o =>
{
host = o.Host;
storagePath = o.StoragePath;
baseUrl = o.BaseUrl;
}).WithNotParsed(err =>
{
foreach (var e in err)
@ -47,6 +49,7 @@ namespace Ombi
{
var config = ctx.ApplicationConfigurations.ToList();
var url = config.FirstOrDefault(x => x.Type == ConfigurationTypes.Url);
var dbBaseUrl = config.FirstOrDefault(x => x.Type == ConfigurationTypes.BaseUrl);
if (url == null)
{
url = new ApplicationConfiguration
@ -65,6 +68,25 @@ namespace Ombi
ctx.SaveChanges();
urlValue = url.Value;
}
if (dbBaseUrl == null)
{
if (baseUrl.HasValue() && baseUrl.StartsWith("/"))
{
dbBaseUrl = new ApplicationConfiguration
{
Type = ConfigurationTypes.BaseUrl,
Value = baseUrl
};
ctx.ApplicationConfigurations.Add(dbBaseUrl);
ctx.SaveChanges();
}
}
else if(!baseUrl.Equals(dbBaseUrl.Value))
{
dbBaseUrl.Value = baseUrl;
ctx.SaveChanges();
}
}
DeleteSchedulesDb();
@ -118,5 +140,8 @@ namespace Ombi
[Option("storage", Required = false, HelpText = "Storage path, where we save the logs and database")]
public string StoragePath { get; set; }
[Option("baseurl", Required = false, HelpText = "The base URL for reverse proxy scenarios")]
public string BaseUrl { get; set; }
}
}

@ -32,6 +32,7 @@ using Ombi.Schedule;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Context;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Serilog;
using Serilog.Events;
@ -176,6 +177,19 @@ namespace Ombi
{
app.UsePathBase(settings.BaseUrl);
}
else
{
// Check if it's in the startup args
var appConfig = serviceProvider.GetService<IApplicationConfigRepository>();
var baseUrl = appConfig.Get(ConfigurationTypes.BaseUrl).Result;
if (baseUrl.Value.HasValue())
{
settings.BaseUrl = baseUrl.Value;
ombiService.SaveSettings(settings);
app.UsePathBase(settings.BaseUrl);
}
}
app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = 1, ServerTimeout = TimeSpan.FromDays(1), ShutdownTimeout = TimeSpan.FromDays(1)});
app.UseHangfireDashboard(settings.BaseUrl.HasValue() ? $"{settings.BaseUrl}/hangfire" : "/hangfire",

Loading…
Cancel
Save