Browse Source

Use <base> to enable relative paths in WebSPA

pull/190/head
Charles Lowell 8 years ago
parent
commit
ed87b6b845
5 changed files with 8 additions and 2 deletions
  1. +1
    -0
      src/Web/WebSPA/AppSettings.cs
  2. +2
    -1
      src/Web/WebSPA/Client/modules/shared/services/configuration.service.ts
  3. +1
    -0
      src/Web/WebSPA/Server/Controllers/HomeController.cs
  4. +3
    -0
      src/Web/WebSPA/Startup.cs
  5. +1
    -1
      src/Web/WebSPA/Views/Shared/_Layout.cshtml

+ 1
- 0
src/Web/WebSPA/AppSettings.cs View File

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


+ 2
- 1
src/Web/WebSPA/Client/modules/shared/services/configuration.service.ts View File

@ -22,7 +22,8 @@ export class ConfigurationService {
constructor(private http: Http, private storageService: StorageService) { }
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) => {
console.log('server settings loaded');
this.serverSettings = response.json();


+ 1
- 0
src/Web/WebSPA/Server/Controllers/HomeController.cs View File

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


+ 3
- 0
src/Web/WebSPA/Startup.cs View File

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


+ 1
- 1
src/Web/WebSPA/Views/Shared/_Layout.cshtml View File

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


Loading…
Cancel
Save