mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
Try the new way of setting up the reverse proxy
This commit is contained in:
parent
a4bbb8853b
commit
6937a90342
5 changed files with 90 additions and 90 deletions
|
@ -2,39 +2,7 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>window["baseHref"] = '/';</script>
|
||||||
function configExists(url) {
|
|
||||||
var req = new XMLHttpRequest();
|
|
||||||
req.open('GET', url, false);
|
|
||||||
req.send();
|
|
||||||
return req.status === 200 && req.responseURL === url;
|
|
||||||
}
|
|
||||||
|
|
||||||
var probePath = 'styles/please-wait.js';
|
|
||||||
var origin = document.location.origin;
|
|
||||||
var pathSegments = document.location.pathname.split('/');
|
|
||||||
|
|
||||||
var basePath = '/'
|
|
||||||
var configFound = false;
|
|
||||||
for (var i = 0; i < pathSegments.length; i++) {
|
|
||||||
var segment = pathSegments[i];
|
|
||||||
if (segment.length > 0) {
|
|
||||||
basePath = basePath + segment + '/';
|
|
||||||
}
|
|
||||||
var fullPath = origin + basePath + probePath;
|
|
||||||
configFound = configExists(fullPath);
|
|
||||||
if (configFound) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var basePathToUse = basePath.substring(0, basePath.length - 1); // trim off the trailing '/'
|
|
||||||
basePathToUse == '' ? '/' : basePathToUse;
|
|
||||||
window["baseHref"] = configFound ? basePathToUse : '/';
|
|
||||||
|
|
||||||
document.write("<base href='" + (configFound ? basePath : '/') + "' />");
|
|
||||||
|
|
||||||
console.log(window["baseHref"]);
|
|
||||||
</script>
|
|
||||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||||
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
|
||||||
<link href="styles/please-wait.css" rel="stylesheet">
|
<link href="styles/please-wait.css" rel="stylesheet">
|
||||||
|
@ -64,7 +32,6 @@
|
||||||
var colors = ["#f44336", "#f44336", "#9c27b0", "#673ab7", "#3f51b5", "#2196f3", "#03a9f4", "#00bcd4", "#009688", "#4caf50", "#cddc39", "#ffeb3b", "#ffc107", "#ff9800", "#ff5722", "#9e9e9e", "#607d8b"];
|
var colors = ["#f44336", "#f44336", "#9c27b0", "#673ab7", "#3f51b5", "#2196f3", "#03a9f4", "#00bcd4", "#009688", "#4caf50", "#cddc39", "#ffeb3b", "#ffc107", "#ff9800", "#ff5722", "#9e9e9e", "#607d8b"];
|
||||||
var bgColor = colors[Math.floor(Math.random() * colors.length)];
|
var bgColor = colors[Math.floor(Math.random() * colors.length)];
|
||||||
window.loading_screen = window.pleaseWait({
|
window.loading_screen = window.pleaseWait({
|
||||||
// logo: "assets/images/logo.png",
|
|
||||||
template: `<div class='pg-loading-inner'>
|
template: `<div class='pg-loading-inner'>
|
||||||
<div class='pg-loading-center-outer'>
|
<div class='pg-loading-center-outer'>
|
||||||
<div class='pg-loading-center-middle'>
|
<div class='pg-loading-center-middle'>
|
||||||
|
|
|
@ -15,9 +15,7 @@ import { AppModule } from "./app/app.module";
|
||||||
|
|
||||||
import { hmrBootstrap } from "./hmr";
|
import { hmrBootstrap } from "./hmr";
|
||||||
declare var module: any;
|
declare var module: any;
|
||||||
// declare var __webpack_require__: any;
|
|
||||||
// __webpack_require__.p = '/ombi';
|
|
||||||
// __webpack_require__ = '/ombi';
|
|
||||||
if (environment.production) {
|
if (environment.production) {
|
||||||
enableProdMode();
|
enableProdMode();
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
|
||||||
<PackageReference Include="System.Security.Cryptography.Csp" Version="4.3.0" />
|
<PackageReference Include="System.Security.Cryptography.Csp" Version="4.3.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="3.1.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="5.0.0-preview.8.20414.8" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -13,6 +13,10 @@ using Ombi.Extensions;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Ombi.Settings.Settings.Models;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Ombi
|
namespace Ombi
|
||||||
{
|
{
|
||||||
|
@ -46,7 +50,10 @@ namespace Ombi
|
||||||
});
|
});
|
||||||
|
|
||||||
Console.WriteLine(HelpOutput(result));
|
Console.WriteLine(HelpOutput(result));
|
||||||
|
if (baseUrl.HasValue())
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Base Url: {baseUrl}");
|
||||||
|
}
|
||||||
UrlArgs = host;
|
UrlArgs = host;
|
||||||
|
|
||||||
var urlValue = string.Empty;
|
var urlValue = string.Empty;
|
||||||
|
@ -61,14 +68,14 @@ namespace Ombi
|
||||||
using (var provider = services.BuildServiceProvider())
|
using (var provider = services.BuildServiceProvider())
|
||||||
{
|
{
|
||||||
var settingsDb = provider.GetRequiredService<SettingsContext>();
|
var settingsDb = provider.GetRequiredService<SettingsContext>();
|
||||||
|
var ombiDb = provider.GetRequiredService<OmbiContext>();
|
||||||
|
|
||||||
if (migrate)
|
if (migrate)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Migrate in progress...");
|
Console.WriteLine("Migrate in progress...");
|
||||||
|
|
||||||
var migrationTasks = new List<Task>();
|
var migrationTasks = new List<Task>();
|
||||||
var externalDb = provider.GetRequiredService<ExternalContext>();
|
var externalDb = provider.GetRequiredService<ExternalContext>();
|
||||||
var ombiDb = provider.GetRequiredService<OmbiContext>();
|
|
||||||
migrationTasks.Add(settingsDb.Database.MigrateAsync());
|
migrationTasks.Add(settingsDb.Database.MigrateAsync());
|
||||||
migrationTasks.Add(ombiDb.Database.MigrateAsync());
|
migrationTasks.Add(ombiDb.Database.MigrateAsync());
|
||||||
migrationTasks.Add(externalDb.Database.MigrateAsync());
|
migrationTasks.Add(externalDb.Database.MigrateAsync());
|
||||||
|
@ -81,7 +88,7 @@ namespace Ombi
|
||||||
|
|
||||||
var config = await settingsDb.ApplicationConfigurations.ToListAsync();
|
var config = await settingsDb.ApplicationConfigurations.ToListAsync();
|
||||||
var url = config.FirstOrDefault(x => x.Type == ConfigurationTypes.Url);
|
var url = config.FirstOrDefault(x => x.Type == ConfigurationTypes.Url);
|
||||||
var dbBaseUrl = config.FirstOrDefault(x => x.Type == ConfigurationTypes.BaseUrl);
|
var ombiSettingsContent = await settingsDb.Settings.FirstOrDefaultAsync(x => x.SettingsName == "OmbiSettings");
|
||||||
var securityToken = config.FirstOrDefault(x => x.Type == ConfigurationTypes.SecurityToken);
|
var securityToken = config.FirstOrDefault(x => x.Type == ConfigurationTypes.SecurityToken);
|
||||||
await CheckSecurityToken(securityToken, settingsDb, instance);
|
await CheckSecurityToken(securityToken, settingsDb, instance);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
@ -118,34 +125,7 @@ namespace Ombi
|
||||||
urlValue = host;
|
urlValue = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbBaseUrl == null)
|
await SortOutBaseUrl(baseUrl, settingsDb, ombiSettingsContent);
|
||||||
{
|
|
||||||
if (baseUrl.HasValue() && baseUrl.StartsWith("/"))
|
|
||||||
{
|
|
||||||
dbBaseUrl = new ApplicationConfiguration
|
|
||||||
{
|
|
||||||
Type = ConfigurationTypes.BaseUrl,
|
|
||||||
Value = baseUrl
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var tran = await settingsDb.Database.BeginTransactionAsync())
|
|
||||||
{
|
|
||||||
settingsDb.ApplicationConfigurations.Add(dbBaseUrl);
|
|
||||||
await settingsDb.SaveChangesAsync();
|
|
||||||
await tran.CommitAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (baseUrl.HasValue() && !baseUrl.Equals(dbBaseUrl.Value))
|
|
||||||
{
|
|
||||||
dbBaseUrl.Value = baseUrl;
|
|
||||||
|
|
||||||
using (var tran = await settingsDb.Database.BeginTransactionAsync())
|
|
||||||
{
|
|
||||||
await settingsDb.SaveChangesAsync();
|
|
||||||
await tran.CommitAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"We are running on {urlValue}");
|
Console.WriteLine($"We are running on {urlValue}");
|
||||||
|
|
||||||
|
@ -197,6 +177,80 @@ namespace Ombi
|
||||||
|
|
||||||
return result.ToString();
|
return result.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task SortOutBaseUrl(string baseUrl, SettingsContext settingsDb, GlobalSettings ombiSettingsContent)
|
||||||
|
{
|
||||||
|
var setBaseUrl = false;
|
||||||
|
if (ombiSettingsContent == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Creating new Settings entity");
|
||||||
|
ombiSettingsContent = new GlobalSettings
|
||||||
|
{
|
||||||
|
SettingsName = "OmbiSettings",
|
||||||
|
Content = JsonConvert.SerializeObject(new OmbiSettings())
|
||||||
|
};
|
||||||
|
using (var tran = await settingsDb.Database.BeginTransactionAsync())
|
||||||
|
{
|
||||||
|
settingsDb.Add(ombiSettingsContent);
|
||||||
|
await settingsDb.SaveChangesAsync();
|
||||||
|
await tran.CommitAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var ombiSettings = JsonConvert.DeserializeObject<OmbiSettings>(ombiSettingsContent.Content);
|
||||||
|
if (ombiSettings == null)
|
||||||
|
{
|
||||||
|
if (baseUrl.HasValue() && baseUrl.StartsWith("/"))
|
||||||
|
{
|
||||||
|
setBaseUrl = true;
|
||||||
|
ombiSettings = new OmbiSettings
|
||||||
|
{
|
||||||
|
BaseUrl = baseUrl
|
||||||
|
};
|
||||||
|
|
||||||
|
ombiSettingsContent.Content = JsonConvert.SerializeObject(ombiSettings);
|
||||||
|
using (var tran = await settingsDb.Database.BeginTransactionAsync())
|
||||||
|
{
|
||||||
|
settingsDb.Update(ombiSettingsContent);
|
||||||
|
await settingsDb.SaveChangesAsync();
|
||||||
|
await tran.CommitAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (baseUrl.HasValue() && !baseUrl.Equals(ombiSettings.BaseUrl))
|
||||||
|
{
|
||||||
|
setBaseUrl = true;
|
||||||
|
ombiSettings.BaseUrl = baseUrl;
|
||||||
|
|
||||||
|
ombiSettingsContent.Content = JsonConvert.SerializeObject(ombiSettings);
|
||||||
|
using (var tran = await settingsDb.Database.BeginTransactionAsync())
|
||||||
|
{
|
||||||
|
settingsDb.Update(ombiSettingsContent);
|
||||||
|
await settingsDb.SaveChangesAsync();
|
||||||
|
await tran.CommitAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (setBaseUrl)
|
||||||
|
{
|
||||||
|
var process = Process.GetCurrentProcess().MainModule.FileName;
|
||||||
|
var ombiInstalledDir = Path.GetDirectoryName(process);
|
||||||
|
var indexPath = Path.Combine(ombiInstalledDir, "ClientApp", "dist", "index.html");
|
||||||
|
if (!File.Exists(indexPath))
|
||||||
|
{
|
||||||
|
var error = $"Can't set the base URL because we cannot find the file at {indexPath}, if you are trying to set a base url please report this on Github!";
|
||||||
|
Console.WriteLine(error);
|
||||||
|
throw new Exception(error);
|
||||||
|
}
|
||||||
|
var indexHtml = await File.ReadAllTextAsync(indexPath);
|
||||||
|
indexHtml = indexHtml.Replace("<script type='text/javascript'>window[\"baseHref\"] = '/';</script>"
|
||||||
|
, $"<script type='text/javascript'>window[\"baseHref\"] = '{baseUrl}';</script><base href=\"{baseUrl}/\">", StringComparison.InvariantCultureIgnoreCase);
|
||||||
|
|
||||||
|
await File.WriteAllTextAsync(indexPath, indexHtml);
|
||||||
|
|
||||||
|
Console.WriteLine($"Wrote new baseurl at {indexPath}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Options
|
public class Options
|
||||||
|
|
|
@ -153,25 +153,6 @@ namespace Ombi
|
||||||
ombiService.SaveSettings(settings);
|
ombiService.SaveSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!settings.Set)
|
|
||||||
{
|
|
||||||
settings.Set = true;
|
|
||||||
settings.CollectAnalyticData = true;
|
|
||||||
ombiService.SaveSettings(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it's in the startup args
|
|
||||||
var appConfig = serviceProvider.GetService<IApplicationConfigRepository>();
|
|
||||||
var baseUrl = appConfig.Get(ConfigurationTypes.BaseUrl);
|
|
||||||
if (baseUrl != null)
|
|
||||||
{
|
|
||||||
if (baseUrl.Value.HasValue())
|
|
||||||
{
|
|
||||||
settings.BaseUrl = baseUrl.Value;
|
|
||||||
ombiService.SaveSettings(settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.BaseUrl.HasValue())
|
if (settings.BaseUrl.HasValue())
|
||||||
{
|
{
|
||||||
app.UsePathBase(settings.BaseUrl);
|
app.UsePathBase(settings.BaseUrl);
|
||||||
|
@ -233,8 +214,8 @@ namespace Ombi
|
||||||
|
|
||||||
app.UseSpa(spa =>
|
app.UseSpa(spa =>
|
||||||
{
|
{
|
||||||
#if DEBUG
|
|
||||||
spa.Options.SourcePath = "ClientApp";
|
spa.Options.SourcePath = "ClientApp";
|
||||||
|
#if DEBUG
|
||||||
spa.UseProxyToSpaDevelopmentServer("http://localhost:3578");
|
spa.UseProxyToSpaDevelopmentServer("http://localhost:3578");
|
||||||
#endif
|
#endif
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue