Created
March 7, 2019 10:02
-
-
Save timdows/33deb8a2d2c4ad0e64d2dfa288c69869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.FileProviders; | |
using System.IO; | |
namespace DAB.Api | |
{ | |
public class Startup | |
{ | |
public Startup(IConfiguration configuration, IHostingEnvironment environment) | |
{ | |
Configuration = configuration; | |
Environment = environment; | |
} | |
public IConfiguration Configuration { get; } | |
public IHostingEnvironment Environment { get; } | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
... | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app) | |
{ | |
... | |
bool isWwwRequest(HttpContext context) => context.Request.Host.Host.ToLower().Contains("www"); | |
var rootPath = Environment.IsDevelopment() | |
? "../AngularApps" | |
: "AngularApps"; | |
var aboutPath = Path.Combine(Environment.ContentRootPath, $"{rootPath}/about"); | |
var webPath = Path.Combine(Environment.ContentRootPath, $"{rootPath}/web"); | |
app.UseWhen(context => isWwwRequest(context), appBuilder => | |
{ | |
appBuilder.UseStaticFiles(new StaticFileOptions() | |
{ | |
FileProvider = new PhysicalFileProvider(aboutPath), | |
}); | |
appBuilder.Run(async context => | |
{ | |
await context.Response.SendFileAsync(Path.Combine(aboutPath, "index.html")); | |
return; | |
}); | |
}); | |
app.UseStaticFiles(new StaticFileOptions() | |
{ | |
FileProvider = new PhysicalFileProvider(webPath), | |
}); | |
app.Run(async context => | |
{ | |
await context.Response.SendFileAsync(Path.Combine(webPath, "index.html")); | |
return; | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment