Use <base> to enable relative paths in WebSPA

This commit is contained in:
Charles Lowell 2017-03-17 15:38:18 -07:00
parent 1efa555825
commit ed87b6b845
5 changed files with 8 additions and 2 deletions

View File

@ -7,6 +7,7 @@ namespace eShopOnContainers.WebSPA
{ {
public class AppSettings public class AppSettings
{ {
public string BaseUrl { get; set; }
public string CatalogUrl { get; set; } public string CatalogUrl { get; set; }
public string OrderingUrl { get; set; } public string OrderingUrl { get; set; }
public string IdentityUrl { get; set; } public string IdentityUrl { get; set; }

View File

@ -22,7 +22,8 @@ export class ConfigurationService {
constructor(private http: Http, private storageService: StorageService) { } constructor(private http: Http, private storageService: StorageService) { }
load() { load() {
let url = "/Home/Configuration"; const baseURI = document.baseURI.endsWith('/') ? document.baseURI : `${document.baseURI}/`;
let url = `${baseURI}Home/Configuration`;
this.http.get(url).subscribe((response: Response) => { this.http.get(url).subscribe((response: Response) => {
console.log('server settings loaded'); console.log('server settings loaded');
this.serverSettings = response.json(); this.serverSettings = response.json();

View File

@ -22,6 +22,7 @@ namespace eShopConContainers.WebSPA.Server.Controllers
public IActionResult Index() public IActionResult Index()
{ {
ViewBag.HashedMain = GetHashedMainDotJs(); ViewBag.HashedMain = GetHashedMainDotJs();
ViewBag.BaseUrl = _settings.Value.BaseUrl;
return View(); return View();
} }

View File

@ -32,6 +32,9 @@ namespace eShopConContainers.WebSPA
} }
Configuration = builder.Build(); Configuration = builder.Build();
var localPath = new Uri(Configuration["ASPNETCORE_URLS"])?.LocalPath ?? "/";
Configuration["BaseUrl"] = localPath;
} }
public static IConfigurationRoot Configuration { get; set;} public static IConfigurationRoot Configuration { get; set;}

View File

@ -5,7 +5,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>eShopConContainers.WebSPA</title> <title>eShopConContainers.WebSPA</title>
<base href="/" /> <base href=@ViewBag.BaseUrl />
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
</head> </head>